CCCC
C bytecode compiler + VM interpreter
Loading...
Searching...
No Matches
Macros | Enumerations | Functions
reflection.h File Reference

Reflection and AST Construction API for CCCC Comptime Functions. More...

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <string.h>
Include dependency graph for reflection.h:

Go to the source code of this file.

Macros

#define __CCCC_TAG(n)   __cccc_##n
 
#define Quote(tmpl, ...)   __builtin_quote(tmpl, ##__VA_ARGS__)
 Parse a C code template string into an AST node, substituting $N / $@N splice points with the given argument nodes.
 
#define QuoteN(tmpl, nodes, count)   __builtin_quote_n(tmpl, nodes, count)
 Array-form quasi-quote that validates the splice count and supports more nodes than Quote's variadic form.
 
#define QuoteLazy(tmpl, ...)   __builtin_quote_lazy(tmpl, ##__VA_ARGS__)
 Capture a C code template and its splice arguments without parsing it; the template is parsed only once spliced into another Quote()/QuoteLazy() template or passed to FunctionSetBody, at that splice site's own scope and loop context.
 
#define QuoteLazyN(tmpl, nodes, count)    __builtin_quote_lazy_n(tmpl, nodes, count)
 Array-form QuoteLazy; validates the splice count at the capture site and supports more nodes than QuoteLazy's variadic form.
 
#define NodeList(nodes, count)   __builtin_node_list(nodes, count)
 Build a ->next-linked node chain from an array, for use as a $@k list-splice argument.
 
#define MacroErrorAt(node, ...)   __builtin_macro_error_at(node, __VA_ARGS__)
 Emit a compiler error pointing at node's source location.
 
#define MacroWarningAt(node, ...)   __builtin_macro_warning_at(node, __VA_ARGS__)
 Emit a compiler warning pointing at node's source location (only under -Wcccc-macro).
 
#define DumpTree(node)   __builtin_dump_tree(node)
 Print a human-readable tree representation of node to stdout.
 
#define DumpTreeToString(node)   __builtin_dump_tree_to_string(node)
 Render the tree representation of node to a heap-allocated string.
 
#define DumpAstGen(node)   __builtin_dump_ast_gen(node)
 Print __builtin_ast_*() builder calls that would reconstruct node.
 
#define DumpAstGenToString(node)   __builtin_dump_ast_gen_to_string(node)
 Render the __builtin_ast_*() builder call sequence for node to a string.
 
#define Gensym(prefix)   __builtin_gensym(prefix)
 Generate a unique identifier string for macro-created symbols.
 
#define MacroExpand1(node)   __builtin_macroexpand_1(node)
 Lisp-style single-step macro expansion (macroexpand-1 semantics).
 
#define MacroExpand(node)   __builtin_macroexpand(node)
 Lisp-style full macro expansion; repeats MacroExpand1 until the form is stable.
 
#define VarargCount()   __builtin_ast_vararg_count()
 Return the number of variadic arguments for the active macro call.
 
#define VarargAt(i)   __builtin_ast_vararg_at(i)
 Return an inline macro's variadic AST argument by zero-based index.
 
#define VarargAsArray()   __builtin_ast_varargs_as_array()
 Return an inline macro's variadic AST arguments as a borrowed array.
 
#define VarargStrAt(i)   __builtin_ast_vararg_str_at(i)
 Return a global-generation macro's stringified variadic argument by index.
 
#define __builtin_dispatch_2(_1, _2, which, ...)   which(_1, _2)
 
#define __builtin_dispatch_3(_1, _2, _3, which, ...)   which(_1, _2, _3)
 
#define CurrentToken()   __builtin_ast_current_token()
 Return the token for the macro invocation currently being executed.
 
#define SyntheticToken(label)   __builtin_ast_synthetic_token(label)
 Create an opaque synthetic source token for generated AST nodes.
 
#define TokenFromNode(node)   __builtin_ast_token_from_node(node)
 Return the opaque source token attached to node.
 
#define SetToken(node, tok)   __builtin_ast_set_token(node, tok)
 Attach an opaque source token to node.
 
#define CopyLocation(dst, src)   __builtin_ast_copy_location(dst, src)
 Copy the source token from src to dst.
 
#define CopyNode(n)   __builtin_ast_copy_node(n)
 Deep-copy an expression or simple statement so it can be linked into a second list.
 
#define FindType(name)   __builtin_ast_find_type(name)
 Look up a type by tag name (struct/union/enum).
 
#define TypeExists(name)   __builtin_ast_type_exists(name)
 Check whether a type is currently in scope by name.
 
#define GetType(name)   __builtin_ast_get_type(name)
 Look up a type by name, resolving any standard base-type spelling ("unsigned char", "long long", ...); an unresolved name is a hard comptime error. Use FindType/TypeExists to probe without erroring.
 
#define GetTypeKind(ty)   __builtin_ast_type_kind(ty)
 Return the TypeKind tag of a type.
 
#define TypeSize(ty)   __builtin_ast_type_size(ty)
 Return sizeof(ty) in bytes.
 
#define TypeAlign(ty)   __builtin_ast_type_align(ty)
 Return _Alignof(ty) in bytes.
 
#define TypeIsUnsigned(ty)   __builtin_ast_type_is_unsigned(ty)
 Test whether an integer type is unsigned.
 
#define TypeIsConst(ty)   __builtin_ast_type_is_const(ty)
 Test whether a type is const-qualified.
 
#define TypeBase(ty)   __builtin_ast_type_base(ty)
 Return the element type of a pointer or array.
 
#define TypeArrayLen(ty)   __builtin_ast_type_array_len(ty)
 Return the fixed length of an array type.
 
#define TypeReturnType(ty)   __builtin_ast_type_return_type(ty)
 Return the return type of a function type.
 
#define TypeParamCount(ty)   __builtin_ast_type_param_count(ty)
 Return the number of declared parameters of a function type.
 
#define TypeParamAt(ty, i)   __builtin_ast_type_param_at(ty, i)
 Return the type of the parameter at the given index.
 
#define TypeIsVariadic(ty)   __builtin_ast_type_is_variadic(ty)
 Test whether a function type is variadic.
 
#define TypeName(ty)   __builtin_ast_type_name(ty)
 Return the user-visible name of a type, if any.
 
#define TypeCName(ty)   __builtin_ast_type_c_name(ty)
 Return a valid C identifier fragment naming ty (for naming generated functions).
 
#define MakeIntLiteral(val)   __builtin_ast_int_literal(val)
 Build an integer literal AST node.
 
#define MakeFloatLiteral(val)   __builtin_ast_float_literal(val)
 Build a floating-point literal AST node.
 
#define MakeStringLiteral(str)   __builtin_ast_string_literal(str)
 Build a string literal AST node.
 
#define StringLiteralValue(node)   __builtin_ast_string_literal_value(node)
 Return the text of a string literal node, or NULL.
 
#define ConstIntValue(node, out)   __builtin_ast_const_int_value(node, out)
 Evaluate an integer constant expression node; false if it is not one.
 
#define ConstUIntValue(node, out)   __builtin_ast_const_uint_value(node, out)
 Like ConstIntValue, for a non-negative or unsigned value up to UINT64_MAX; false for a negative signed value.
 
#define MakeVarRef(name)   __builtin_ast_var_ref(name)
 Build a variable reference AST node.
 
#define MakeParamRef(fn, name)   __builtin_ast_param_ref(fn, name)
 Build a reference to a function parameter by name.
 
#define MakeBinary(op, l, r)   __builtin_ast_binary(op, l, r)
 Build a binary operation AST node.
 
#define MakeUnary(op, operand)   __builtin_ast_unary(op, operand)
 Build a unary operation AST node.
 
#define MakeCast(expr, ty)   __builtin_ast_cast(expr, ty)
 Build a type cast AST node.
 
#define MakeCond(c, t, e)   __builtin_ast_cond(c, t, e)
 Build a ternary conditional expression node (c ? t : e).
 
#define MakeNull()   __builtin_ast_null()
 Build a typed null pointer node: (void *)0.
 
#define MakeSizeofType(ty)   __builtin_ast_sizeof_type(ty)
 Emit sizeof(ty) as a compile-time integer literal.
 
#define MakeAlignofType(ty)   __builtin_ast_alignof_type(ty)
 Emit _Alignof(ty) as a compile-time integer literal.
 
#define MakeSizeofExpr(expr)   __builtin_ast_sizeof_expr(expr)
 Emit sizeof(expr): resolves the expression's type then its size.
 
#define MakeSubscript(arr, idx)   __builtin_ast_subscript(arr, idx)
 Build an array subscript node: arr[idx], desugared as *(arr+idx).
 
#define MakeComma(lhs, rhs)   __builtin_ast_comma(lhs, rhs)
 Build a comma expression: evaluate lhs, yield rhs.
 
#define MakeReturn(expr)   __builtin_ast_return(expr)
 Build a return statement node.
 
#define MakeBlock(stmts, count)   __builtin_ast_block(stmts, count)
 Build a block (compound statement) node.
 
#define __builtin_block_add_stmt_1(stmt, _ignored)    __builtin_ast_block_add_current_stmt(stmt)
 
#define __builtin_block_add_stmt_2(block, stmt)    __builtin_ast_block_add_stmt(block, stmt)
 
#define BlockAddStmt(...)
 Append a statement to a block.
 
#define MakeIf(c, t, e)   __builtin_ast_if(c, t, e)
 Build an if statement node.
 
#define MakeSwitch(cond)   __builtin_ast_switch(cond)
 Build a switch statement node.
 
#define __builtin_switch_add_case_2(v, b, _ignored)    __builtin_ast_switch_add_current_case(v, b)
 
#define __builtin_switch_add_case_3(sw, v, b)    __builtin_ast_switch_add_case(sw, v, b)
 
#define SwitchAddCase(...)
 Append a case to a switch statement.
 
#define __builtin_switch_set_default_1(b, _ignored)    __builtin_ast_switch_set_current_default(b)
 
#define __builtin_switch_set_default_2(sw, b)    __builtin_ast_switch_set_default(sw, b)
 
#define SwitchSetDefault(...)
 Set the default case for a switch statement.
 
#define MakeExprStmt(expr)   __builtin_ast_expr_stmt(expr)
 Build an expression statement node.
 
#define MakeLocalVar(name, ty)   __builtin_ast_local_var(name, ty)
 Declare a named local variable in the current function scope.
 
#define MakeLocalVarUnique(ty)   __builtin_ast_local_var_unique(ty)
 Declare a hygienic (gensym'd) local variable in the current function scope.
 
#define MakeAssign(target, value)   __builtin_ast_assign(target, value)
 Build an assignment node (target = value).
 
#define MakeMember(obj, name)   __builtin_ast_member(obj, name)
 Create a struct/union member access node (obj.name).
 
#define MakeFuncCall(callee, args, n)   __builtin_ast_funcall(callee, args, n)
 Create a function call node.
 
#define Memcpy(dst, src, n)
 Build a call node to memcpy(dst, src, n).
 
#define Strlen(s)    __builtin_ast_funcall(__builtin_ast_var_ref("strlen"), (Node *[]){(s)}, 1)
 Build a call node to strlen(s).
 
#define Strcmp(a, b)
 Build a call node to strcmp(a, b).
 
#define MakeWhile(cond, body)   __builtin_ast_while(cond, body)
 Create a while loop node.
 
#define MakeFor(init, cond, inc, body)   __builtin_ast_for(init, cond, inc, body)
 Create a for loop node.
 
#define MakeDoWhile(body, cond)   __builtin_ast_do_while(body, cond)
 Create a do-while loop node.
 
#define LoopSetBody(loop, body)   __builtin_ast_loop_set_body(loop, body)
 Attach body to loop (from MakeWhile/MakeFor/MakeDoWhile).
 
#define WithLoop(loop)
 Scoped block establishing loop as the current loop context, so an eager Quote("break;")/Quote("continue;") call inside the block resolves against loop's own break/continue targets.
 
#define MakePointer(base)   __builtin_ast_make_pointer(base)
 Build a pointer-to-base type.
 
#define MakeArray(base, len)   __builtin_ast_make_array(base, len)
 Build a fixed-length array type.
 
#define MakeFuncPtrType(ret, params, n)    __builtin_ast_make_func_ptr_type(ret, params, n)
 Build a pointer-to-function type, e.g. "T (*)(T)".
 
#define MakeConst(ty)   __builtin_ast_make_const(ty)
 Return a const-qualified copy of ty.
 
#define MakeVolatile(ty)   __builtin_ast_make_volatile(ty)
 Return a volatile-qualified copy of ty.
 
#define EnumCount(ty)   __builtin_ast_enum_count(ty)
 Return the number of constants in an enum type.
 
#define EnumAt(ty, i)   __builtin_ast_enum_at(ty, i)
 Return the enum constant at a given index.
 
#define EnumFind(ty, name)   __builtin_ast_enum_find(ty, name)
 Look up an enum constant by name.
 
#define EnumConstantName(ec)   __builtin_ast_enum_constant_name(ec)
 Return the name of an enum constant.
 
#define EnumConstantValue(ec)   __builtin_ast_enum_constant_value(ec)
 Return the integer value of an enum constant.
 
#define EnumName(ty)   __builtin_ast_enum_name(ty)
 Return the tag name of an enum type.
 
#define EnumValueCount(ty)   __builtin_ast_enum_value_count(ty)
 Return the number of values in an enum type.
 
#define EnumValueName(ty, i)   __builtin_ast_enum_value_name(ty, i)
 Return the name of the enum constant at the given index.
 
#define EnumValue(ty, i)   __builtin_ast_enum_value(ty, i)
 Return the integer value of the enum constant at the given index.
 
#define EnumToString(ty, expr)   __builtin_ast_enum_to_string_switch(ty, expr)
 Build a switch over ty's constants returning each constant's name as a string.
 
#define EnumFromString(ty, expr)   __builtin_ast_enum_from_string_chain(ty, expr)
 Build an if-chain comparing expr against each constant's name, returning the matching value.
 
#define StructMemberCount(ty)   __builtin_ast_struct_member_count(ty)
 Return the number of members of a struct or union type.
 
#define StructMemberAt(ty, i)   __builtin_ast_struct_member_at(ty, i)
 Return the member at the given index.
 
#define StructMemberFind(ty, name)   __builtin_ast_struct_member_find(ty, name)
 Look up a struct or union member by name.
 
#define MemberName(m)   __builtin_ast_member_name(m)
 Return the name of a struct/union member.
 
#define MemberType(m)   __builtin_ast_member_type(m)
 Return the type of a struct/union member.
 
#define MemberOffset(m)   __builtin_ast_member_offset(m)
 Return the byte offset of a struct/union member.
 
#define MemberIsBitfield(m)   __builtin_ast_member_is_bitfield(m)
 Test whether a member is a bitfield.
 
#define MemberBitfieldWidth(m)   __builtin_ast_member_bitfield_width(m)
 Return the bit width of a bitfield member.
 
#define __builtin_foreach_member_body(type, varname, body, uid)
 
#define __builtin_foreach_member_uid(type, varname, body, uid)    __builtin_foreach_member_body(type, varname, body, uid)
 
#define ForeachMember(type, varname, body)    __builtin_foreach_member_uid(type, varname, body, __COUNTER__)
 Host-side loop over the members of a struct/union type, evaluated at macro-execution (compile) time.
 
#define OffsetofChain(type, ...)
 Compute the byte offset of a (possibly nested) member chain as a MakeIntLiteral AST node.
 
#define FindGlobal(name)   __builtin_ast_find_global(name)
 Look up a global symbol by name.
 
#define GlobalCount()   __builtin_ast_global_count()
 Return the total number of global symbols.
 
#define GlobalAt(i)   __builtin_ast_global_at(i)
 Return the global symbol at the given index.
 
#define ObjName(obj)   __builtin_ast_obj_name(obj)
 Return the name of a global object.
 
#define ObjType(obj)   __builtin_ast_obj_type(obj)
 Return the type of a global object.
 
#define ObjIsFunction(obj)   __builtin_ast_obj_is_function(obj)
 Test whether a global object is a function.
 
#define ObjIsDefinition(obj)   __builtin_ast_obj_is_definition(obj)
 Test whether a global object has a definition.
 
#define ObjIsStatic(obj)   __builtin_ast_obj_is_static(obj)
 Test whether a global object has internal (static) linkage.
 
#define FnBody(fn)   __builtin_ast_function_body(fn)
 Return the top-level block of a function definition.
 
#define FnParamCount(fn)   __builtin_ast_function_param_count(fn)
 Return the number of parameters of a function definition.
 
#define FnParamAt(fn, i)   __builtin_ast_function_param_at(fn, i)
 Return a parameter of a function definition, in declaration order.
 
#define FnLocalCount(fn)   __builtin_ast_function_local_count(fn)
 Return the number of source-level locals of a function definition.
 
#define FnLocalAt(fn, i)   __builtin_ast_function_local_at(fn, i)
 Return a local variable of a function definition, in declaration order.
 
#define ObjNext(obj)   __builtin_ast_obj_next(obj)
 Return the next Obj in the list that holds obj.
 
#define GetNodeKind(node)   __builtin_ast_node_kind(node)
 Return the kind of a node.
 
#define GetNodeType(node)   __builtin_ast_node_type(node)
 Return the resolved type of an expression node.
 
#define NodeNext(node)   __builtin_ast_node_next(node)
 Return the next node in a statement or argument list.
 
#define NodeLhs(node)   __builtin_ast_node_lhs(node)
 Return the left operand (or sole operand) of a node.
 
#define NodeRhs(node)   __builtin_ast_node_rhs(node)
 Return the right operand of a node.
 
#define NodeBody(node)   __builtin_ast_node_body(node)
 Return the statement list of an NK_BLOCK or NK_STMT_EXPR.
 
#define NodeCond(node)   __builtin_ast_node_cond(node)
 Return the condition of an if, loop, switch or ?: node.
 
#define NodeThen(node)   __builtin_ast_node_then(node)
 Return the then-branch of an if or ?: node, or the body of a loop or switch.
 
#define NodeElse(node)   __builtin_ast_node_else(node)
 Return the else-branch of an if or ?: node.
 
#define NodeInit(node)   __builtin_ast_node_init(node)
 Return the initialiser of a for node.
 
#define NodeInc(node)   __builtin_ast_node_inc(node)
 Return the increment of a for node.
 
#define BlockCount(block)   __builtin_ast_block_count(block)
 Return the number of statements in an NK_BLOCK or NK_STMT_EXPR.
 
#define BlockAt(block, i)   __builtin_ast_block_at(block, i)
 Return a statement of an NK_BLOCK or NK_STMT_EXPR.
 
#define CallCallee(call)   __builtin_ast_call_callee(call)
 Return the callee expression of a call.
 
#define CallArgCount(call)   __builtin_ast_call_arg_count(call)
 Return the number of arguments of a call.
 
#define CallArgAt(call, i)   __builtin_ast_call_arg_at(call, i)
 Return an argument of a call.
 
#define NodeIntValue(node)   __builtin_ast_node_int_value(node)
 Return the value of an integer NK_NUM literal.
 
#define NodeFloatValue(node)   __builtin_ast_node_float_value(node)
 Return the value of a floating NK_NUM literal.
 
#define NodeVarObj(node)   __builtin_ast_node_var_obj(node)
 Return the variable an NK_VAR (or NK_MEMZERO) node refers to.
 
#define NodeMember(node)   __builtin_ast_node_member(node)
 Return the member an NK_MEMBER node selects.
 
#define SwitchCaseCount(sw)   __builtin_ast_switch_case_count(sw)
 Return the number of case labels of a switch (excluding default).
 
#define SwitchCaseAt(sw, i)   __builtin_ast_switch_case_at(sw, i)
 Return a case label of a switch, in source order.
 
#define SwitchDefault(sw)   __builtin_ast_switch_default(sw)
 Return the default label of a switch.
 
#define CaseBegin(node)   __builtin_ast_case_begin(node)
 Return the first value of an NK_CASE label.
 
#define CaseEnd(node)   __builtin_ast_case_end(node)
 Return the last value of an NK_CASE label (equal to CaseBegin unless a GNU range).
 
#define CaseBody(node)   __builtin_ast_case_body(node)
 Return the statement that follows an NK_CASE label.
 
#define MacroCallName(node)   __builtin_ast_macro_call_name(node)
 Return the macro name of a not-yet-expanded NK_MACRO_CALL.
 
#define MacroCallArgCount(node)   __builtin_ast_macro_call_arg_count(node)
 Return the argument count of an NK_MACRO_CALL.
 
#define MacroCallArgAt(node, i)   __builtin_ast_macro_call_arg_at(node, i)
 Return an argument of an NK_MACRO_CALL.
 
#define StripImplicit(node)   __builtin_ast_node_strip_implicit(node)
 Peel compiler-inserted casts and call wrappers off a node.
 
#define LabelName(node)   __builtin_ast_label_name(node)
 Return the name of an NK_GOTO, NK_LABEL or NK_LABEL_VAL.
 
#define GotoJumpKind(node)   __builtin_ast_goto_jump_kind(node)
 Return which statement an NK_GOTO came from (AST_JUMP_*).
 
#define AsmTemplate(node)   __builtin_ast_asm_template(node)
 Return the template string of an NK_ASM statement.
 
#define AsmOutputCount(node)   __builtin_ast_asm_output_count(node)
 Return the number of output operands of an NK_ASM statement.
 
#define AsmInputCount(node)   __builtin_ast_asm_input_count(node)
 Return the number of input operands of an NK_ASM statement.
 
#define AsmOperandConstraint(node, i)    __builtin_ast_asm_operand_constraint(node, i)
 Return the constraint string of an asm operand.
 
#define AsmOperandName(node, i)   __builtin_ast_asm_operand_name(node, i)
 Return the symbolic name of an asm operand, or NULL.
 
#define AsmOperandExpr(node, i)   __builtin_ast_asm_operand_expr(node, i)
 Return the expression of an asm operand.
 
#define AsmClobberCount(node)   __builtin_ast_asm_clobber_count(node)
 Return the number of clobbers of an NK_ASM statement.
 
#define AsmClobberAt(node, i)   __builtin_ast_asm_clobber_at(node, i)
 Return a clobber of an NK_ASM statement.
 
#define AsmIsVolatile(node)   __builtin_ast_asm_is_volatile(node)
 Return whether an NK_ASM statement is written volatile.
 
#define AsmIsGoto(node)   __builtin_ast_asm_is_goto(node)
 Return whether an NK_ASM statement is an asm goto.
 
#define AsmGotoLabelCount(node)   __builtin_ast_asm_goto_label_count(node)
 Return the number of jump labels of an asm goto.
 
#define AsmGotoLabelAt(node, i)   __builtin_ast_asm_goto_label_at(node, i)
 Return a jump label name of an asm goto.
 
#define AtomicOrder(node)   __builtin_ast_atomic_order(node)
 Return the __ATOMIC_* memory order of an atomic node, -1 for other kinds.
 
#define AtomicFailOrder(node)   __builtin_ast_atomic_fail_order(node)
 Return the failure memory order of an NK_CAS, -1 for other kinds.
 
#define AtomicIsWeak(node)   __builtin_ast_atomic_is_weak(node)
 Return whether an NK_CAS was written as a weak compare-exchange.
 
#define CasAddr(node)   __builtin_ast_cas_addr(node)
 Return the address operand of an NK_CAS.
 
#define CasExpected(node)   __builtin_ast_cas_expected(node)
 Return the expected-value operand of an NK_CAS.
 
#define CasDesired(node)   __builtin_ast_cas_desired(node)
 Return the desired-value operand of an NK_CAS.
 
#define FenceIsSignal(node)   __builtin_ast_fence_is_signal(node)
 Return whether an NK_FENCE is a signal fence.
 
#define BitopOp(node)   __builtin_ast_bitop_op(node)
 Return the operation (AST_BITOP_*) of an NK_BITOP.
 
#define BitopWidth(node)   __builtin_ast_bitop_width(node)
 Return the bit width of an NK_BITOP's builtin.
 
#define OverflowOp(node)   __builtin_ast_overflow_op(node)
 Return the operation (AST_OVERFLOW_*) of an NK_OVERFLOW_ARITH.
 
#define OverflowResultPtr(node)   __builtin_ast_overflow_result_ptr(node)
 Return the result pointer of an NK_OVERFLOW_ARITH.
 
#define GetAttrTargetKind(target)   __builtin_attr_target_kind(target)
 Return the kind of declaration decorated by a custom attribute.
 
#define AttrTargetName(target)   __builtin_attr_target_name(target)
 Return the decorated declaration's source name, when available.
 
#define AttrTargetType(target)   __builtin_attr_target_type(target)
 Return the decorated declaration's type.
 
#define AttrTargetObj(target)   __builtin_attr_target_obj(target)
 Return the decorated function or global object, or NULL for type targets.
 
#define AttrTargetToken(target)   __builtin_attr_target_token(target)
 Return a source token for the decorated declaration.
 
#define AttrTargetMember(target)   __builtin_attr_target_member(target)
 Return the attributed member of an ATTR_TARGET_MEMBER target.
 
#define AttrTargetOwner(target)   __builtin_attr_target_owner(target)
 Return the struct or union declaring an ATTR_TARGET_MEMBER target's member, or the function type of an ATTR_TARGET_PARAM target.
 
#define AttrTargetParam(target)   __builtin_attr_target_param(target)
 Return the attributed parameter's type of an ATTR_TARGET_PARAM target.
 
#define AttrTargetParamIndex(target)   __builtin_attr_target_param_index(target)
 Return the position of an ATTR_TARGET_PARAM target in its parameter list, or -1.
 
#define MemberHasAttr(m, name)   __builtin_ast_member_has_attr(m, name)
 Return 1 if the member carries the custom attribute name.
 
#define MemberAttrArgCount(m, name)   __builtin_ast_member_attr_arg_count(m, name)
 Return the argument count of the first use of name, or -1 if absent.
 
#define MemberAttrArg(m, name, i)   __builtin_ast_member_attr_arg(m, name, i)
 Return argument i of the first use of name as an expression node.
 
#define MemberAttrCount(m)   __builtin_ast_member_attr_count(m)
 Return the number of custom attribute uses on the member.
 
#define MemberAttrNameAt(m, i)   __builtin_ast_member_attr_name_at(m, i)
 Return the name of attribute use i.
 
#define MemberAttrArgCountAt(m, i)   __builtin_ast_member_attr_arg_count_at(m, i)
 Return the argument count of attribute use i.
 
#define MemberAttrArgAt(m, i, j)   __builtin_ast_member_attr_arg_at(m, i, j)
 Return argument j of attribute use i as an expression node.
 
#define ParamHasAttr(p, name)   __builtin_ast_param_has_attr(p, name)
 Return 1 if the parameter carries the custom attribute name.
 
#define ParamAttrArgCount(p, name)   __builtin_ast_param_attr_arg_count(p, name)
 Return the argument count of the first use of name, or -1 if absent.
 
#define ParamAttrArg(p, name, i)   __builtin_ast_param_attr_arg(p, name, i)
 Return argument i of the first use of name as an expression node.
 
#define ParamAttrCount(p)   __builtin_ast_param_attr_count(p)
 Return the number of custom attribute uses on the parameter.
 
#define ParamAttrNameAt(p, i)   __builtin_ast_param_attr_name_at(p, i)
 Return the name of attribute use i.
 
#define ParamAttrArgCountAt(p, i)   __builtin_ast_param_attr_arg_count_at(p, i)
 Return the argument count of attribute use i.
 
#define ParamAttrArgAt(p, i, j)   __builtin_ast_param_attr_arg_at(p, i, j)
 Return argument j of attribute use i as an expression node.
 
#define MakeFunction(name, ret_type)   __builtin_ast_function(name, ret_type)
 Create a new function object, automatically added to the globals list.
 
#define PublishNode(decl)
 Make a generated declaration visible at the current source position.
 
#define PublishNodeAt(decl, tok)
 Like PublishNode, but attaches an explicit diagnostic token.
 
#define EmitDirective(line)   __builtin_emit_directive(line)
 Emit one raw preprocessor directive line into generated output.
 
#define FunctionAddParam(fn, name, type)    __builtin_ast_function_add_param(fn, name, type)
 Add a parameter to a function.
 
#define FunctionSetBody(fn, body)   __builtin_ast_function_set_body(fn, body)
 Set the body of a function.
 
#define FunctionSetStatic(fn, is_static)    __builtin_ast_function_set_static(fn, is_static)
 Set whether a function has static linkage.
 
#define FunctionSetInline(fn, is_inline)    __builtin_ast_function_set_inline(fn, is_inline)
 Set whether a function is inline.
 
#define FunctionSetVariadic(fn, is_variadic)    __builtin_ast_function_set_variadic(fn, is_variadic)
 Set whether a function is variadic.
 
#define FunctionPrototype(name, ret)   __builtin_ast_function_prototype(name, ret)
 Create a function forward declaration (prototype) without a body.
 
#define AddAttribute(fn, text)   __builtin_ast_add_attribute(fn, text)
 Apply an attribute string to a programmatically created function.
 
#define MarkAsTest(fn)   AddAttribute(fn, "cccc::test")
 Shorthand for AddAttribute(fn, "cccc::test").
 
#define MarkAsBuild(fn)   AddAttribute(fn, "cccc::build")
 Shorthand for AddAttribute(fn, "cccc::build").
 
#define MarkAsBuildTarget(fn, kind)    __builtin_ast_add_build_target_attr(fn, kind)
 Mark fn as a [[cccc::build_target]] factory of the given kind.
 
#define MakeStruct(name)   __builtin_ast_make_struct(name)
 Create and expose a new named struct type.
 
#define MakeUnion(name)   __builtin_ast_make_union(name)
 Create and expose a new named union type.
 
#define __builtin_struct_add_field_2(name, field_type, _ignored)    __builtin_ast_struct_add_current_field(name, field_type)
 
#define __builtin_struct_add_field_3(ty, name, field_type)    __builtin_ast_struct_add_field(ty, name, field_type)
 
#define StructAddField(...)
 Append a field to a struct or union and recompute its layout.
 
#define MakeEnum(name)   __builtin_ast_make_enum(name)
 Create and expose a new named enum type.
 
#define __builtin_enum_add_constant_2(name, value, _ignored)    __builtin_ast_enum_add_current_constant(name, value)
 
#define __builtin_enum_add_constant_3(ty, name, value)    __builtin_ast_enum_add_constant(ty, name, value)
 
#define EnumAddConstant(...)
 Add a named constant to an enum type and expose it in scope.
 
#define MakeTypedef(name, underlying)    __builtin_ast_make_typedef(name, underlying)
 Register a typedef alias for a type and expose it in scope.
 
#define GetComptimeInt(name)   __builtin_get_comptime_int(name)
 Read an integer-typed #pragma comptime variable's value at compile time.
 
#define GetComptimeFloat(name)   __builtin_get_comptime_float(name)
 Read a float/double-typed #pragma comptime variable's value at compile time.
 
#define GetComptimeVar(name)   __builtin_get_comptime_var(name)
 Read a comptime scalar variable as an AST literal node.
 
#define GetComptimePtr(name)   __builtin_get_comptime_ptr(name)
 Return the address of a comptime variable as a generated-code AST pointer node.
 
#define GetComptimeMember(var, field)   __builtin_get_comptime_member(var, field)
 Read a named field from a comptime struct variable as an AST literal node.
 
#define GetConstexprValue(name)   __builtin_get_constexpr_value(name)
 Read the evaluated initializer of a global constexpr variable as an AST literal node.
 
#define CompoundLiteral(ty, ...)
 Build a positional compound literal; element count is inferred from the argument list.
 
#define InitArray(elem_ty, ...)
 Build an array compound literal with an explicit element type.
 
#define InitStruct(ty, fields, values, n)    __builtin_ast_init_struct(ty, fields, values, n)
 Build a designated struct/union initializer; unmentioned fields are zero-initialised.
 
#define Serialize(ty, expr, buf)   __builtin_ast_serialize(ty, expr, buf)
 Build a block of memcpy() calls copying expr (of type ty) into buf.
 
#define Deserialize(ty, buf)   __builtin_ast_deserialize(ty, buf)
 Build an expression that reconstructs a ty value from buf.
 
#define GlobalVar(name, ty)   __builtin_ast_global_var(name, ty)
 Create a new named global variable definition.
 
#define GlobalVarSetInitData(var, data, len)    __builtin_ast_global_var_set_init_data(var, data, len)
 Set the initial data for a generated global variable.
 
#define GlobalVarSetStatic(var, is_static)    __builtin_ast_global_var_set_static(var, is_static)
 Set the static (internal linkage) flag on a generated global.
 
#define WithFn(fn)
 Block helper: establishes fn as the current function-building context so Quote("return x;") applies the correct return-type cast.
 
#define WithBlock(block)
 Block helper: establishes block as the current statement-append context so BlockAddStmt(stmt) appends to it.
 
#define WithStruct(ty)
 Block helper: establishes ty as the current field-add context so StructAddField(name, ty) appends to it.
 
#define WithSwitch(sw)
 Block helper: establishes sw as the current case/default context so SwitchAddCase / SwitchSetDefault populate it.
 
#define WithEnum(ty)
 Block helper: establishes ty as the current constant-add context so EnumAddConstant(name, value) appends to it.
 
#define GenerateSum(elem_type)   __builtin_generate_sum(elem_type)
 Publish T sum_T(T *arr, size_t n) summing all elements.
 
#define GenerateMap(elem_type)   __builtin_generate_map(elem_type)
 Publish void map_T(T *arr, size_t n, T *out, T (*f)(T)).
 
#define GenerateReduce(elem_type)   __builtin_generate_reduce(elem_type)
 Publish T reduce_T(T *arr, size_t n, T init, T (*f)(T, T)).
 
#define GenerateFilter(elem_type)   __builtin_generate_filter(elem_type)
 Publish void filter_T(T *arr, size_t n, T *out, size_t *out_n, bool (*pred)(T)).
 

Enumerations

enum  TypeKind {
  TK_VOID = 0 , TK_BOOL = 1 , TK_CHAR = 2 , TK_SHORT = 3 ,
  TK_INT = 4 , TK_LONG = 5 , TK_FLOAT = 6 , TK_DOUBLE = 7 ,
  TK_LDOUBLE = 8 , TK_ENUM = 9 , TK_PTR = 10 , TK_FUNC = 11 ,
  TK_ARRAY = 12 , TK_VLA = 13 , TK_STRUCT = 14 , TK_UNION = 15
}
 Discriminates the kind of a Type: primitive, pointer, array, function, struct/union, or enum. More...
 
enum  NodeKind {
  NK_NULL_EXPR = 0 , NK_ADD = 1 , NK_SUB = 2 , NK_MUL = 3 ,
  NK_DIV = 4 , NK_NEG = 5 , NK_MOD = 6 , NK_BITAND = 7 ,
  NK_BITOR = 8 , NK_BITXOR = 9 , NK_SHL = 10 , NK_SHR = 11 ,
  NK_EQ = 12 , NK_NE = 13 , NK_LT = 14 , NK_LE = 15 ,
  NK_ASSIGN = 16 , NK_COND = 17 , NK_COMMA = 18 , NK_MEMBER = 19 ,
  NK_ADDR = 20 , NK_DEREF = 21 , NK_NOT = 22 , NK_BITNOT = 23 ,
  NK_LOGAND = 24 , NK_LOGOR = 25 , NK_RETURN = 26 , NK_IF = 27 ,
  NK_FOR = 28 , NK_DO = 29 , NK_SWITCH = 30 , NK_CASE = 31 ,
  NK_BLOCK = 32 , NK_GOTO = 33 , NK_GOTO_EXPR = 34 , NK_LABEL = 35 ,
  NK_LABEL_VAL = 36 , NK_FUNCALL = 37 , NK_EXPR_STMT = 38 , NK_STMT_EXPR = 39 ,
  NK_VAR = 40 , NK_VLA_PTR = 41 , NK_NUM = 42 , NK_CAST = 43 ,
  NK_MEMZERO = 44 , NK_ASM = 45 , NK_CAS = 46 , NK_EXCH = 47 ,
  NK_FRAME_ADDR = 48 , NK_BLOCK_LITERAL = 49 , NK_BLOCK_CALL = 50 , NK_MACRO_CALL = 51 ,
  NK_COMPLEX = 52 , NK_UNREACHABLE = 53 , NK_BITOP = 54 , NK_OVERFLOW_ARITH = 55 ,
  NK_INIT_SPLICE = 56 , NK_ALOAD = 57 , NK_ASTORE = 58 , NK_RETURN_ADDR = 59 ,
  NK_DYNOBJ_SIZE = 60 , NK_CONVERTVECTOR = 61 , NK_DECIMAL_TO_CHARS = 62 , NK_FENCE = 63 ,
  NK_QUOTE_LAZY = 64 , NK_DYNAMIC_CHECK = 65 , NK_VA_NAMED_COUNT = 66
}
 Discriminates the operator/statement kind of a Node, e.g. as passed to MakeBinary / MakeUnary, returned by GetNodeKind, or matched against a node's ->kind field. More...
 
enum  AstJumpKind { AST_JUMP_GOTO = 1 , AST_JUMP_BREAK = 2 , AST_JUMP_CONTINUE = 3 }
 Which statement an NK_GOTO node came from, returned by GotoJumpKind(node). More...
 
enum  AstBitop {
  AST_BITOP_CLZ = 1 , AST_BITOP_CTZ = 2 , AST_BITOP_POPCOUNT = 3 , AST_BITOP_PARITY = 4 ,
  AST_BITOP_FFS = 5 , AST_BITOP_BSWAP = 6
}
 The operation of an NK_BITOP node, returned by BitopOp(node). More...
 
enum  AstOverflowOp { AST_OVERFLOW_ADD = 1 , AST_OVERFLOW_SUB = 2 , AST_OVERFLOW_MUL = 3 }
 The operation of an NK_OVERFLOW_ARITH node, returned by OverflowOp(node). More...
 
enum  AttrTargetKind {
  ATTR_TARGET_TYPEDEF = 1 , ATTR_TARGET_TYPE = 2 , ATTR_TARGET_FUNCTION = 3 , ATTR_TARGET_GLOBAL = 4 ,
  ATTR_TARGET_MEMBER = 5 , ATTR_TARGET_PARAM = 6
}
 Discriminates the kind of declaration an AttrTarget refers to, returned by GetAttrTargetKind(target) inside a custom @attribute handler. More...
 

Functions

struct __CCCC_TAG (VirtualMachine) VirtualMachine
 Opaque compiler/VM instance. Macro authors never see or pass this; functions that need it read it internally from a process-global set for the duration of macro execution.
 
struct __CCCC_TAG (Type) Type
 Opaque compiler type descriptor (primitive, pointer, array, function, struct/union, or enum). Inspect it with the GetTypeKind / Type* family of macros.
 
struct __CCCC_TAG (Node) Node
 Opaque AST node (expression, statement, or literal). Built with the Make* family of macros and spliced into the compiled program by returning it from a comptime function or via PublishNode.
 
struct __CCCC_TAG (Obj) Obj
 Opaque global symbol (a function or global variable). Created by MakeFunction / GlobalVar, or looked up with FindGlobal / GlobalAt.
 
struct __CCCC_TAG (Member) Member
 Opaque struct/union member descriptor, returned by StructMemberAt / StructMemberFind and inspected with the Member* family of macros.
 
struct __CCCC_TAG (EnumConstant) EnumConstant
 Opaque enum constant descriptor, returned by EnumAt / EnumFind and inspected with EnumConstantName / EnumConstantValue.
 
struct __CCCC_TAG (Token) Token
 Opaque source-location handle attached to AST nodes for diagnostics. Obtained via CurrentToken / SyntheticToken / TokenFromNode and attached with SetToken.
 
struct __CCCC_TAG (AttrTarget) AttrTarget
 Opaque handle to the declaration a custom @attribute handler was invoked on. Inspected with the AttrTarget* family of macros inside a function registered via @comptime(attribute("...")).
 
const char * __builtin_gensym (const char *prefix)
 Generate a unique identifier string for macro-created symbols.
 
Node * __builtin_macroexpand_1 (Node *node)
 Lisp-style single-step macro expansion (macroexpand-1 semantics).
 
Node * __builtin_macroexpand (Node *node)
 Lisp-style full macro expansion.
 
int __builtin_ast_vararg_count (void)
 Return the number of variadic arguments for the active macro call.
 
Node * __builtin_ast_vararg_at (int index)
 Return an inline macro's variadic AST argument by zero-based index.
 
Node ** __builtin_ast_varargs_as_array (void)
 Return an inline macro's variadic AST arguments as an array.
 
const char * __builtin_ast_vararg_str_at (int index)
 Return a global-generation macro's stringified variadic argument.
 
Token * __builtin_ast_current_token (void)
 Return the token for the macro invocation currently being executed.
 
Token * __builtin_ast_synthetic_token (const char *label)
 Create an opaque synthetic source token for generated AST nodes.
 
Token * __builtin_ast_token_from_node (Node *node)
 Return the opaque source token attached to a node.
 
Node * __builtin_ast_set_token (Node *node, Token *tok)
 Attach an opaque source token to a node.
 
Node * __builtin_ast_copy_location (Node *dst, Node *src)
 Copy the source token from one node to another.
 
Node * __builtin_ast_copy_node (Node *n)
 Deep-copy an expression or statement tree.
 
void __builtin_macro_error_at (Node *node, const char *fmt,...) __attribute__((format(printf
 Emit a compiler error pointing at the source location of a node.
 
void void __builtin_macro_warning_at (Node *node, const char *fmt,...) __attribute__((format(printf
 Emit a compiler warning pointing at the source location of a node.
 
void void Node * __builtin_quote (const char *tmpl,...)
 Parse a C code template string into an AST node, substituting splice points with the provided argument nodes.
 
Node * __builtin_quote_n (const char *tmpl, Node **nodes, int count)
 Array-form quasi-quote that validates the caller-provided splice count and supports larger node arrays than the variadic form.
 
Node * __builtin_quote_lazy (const char *tmpl,...)
 Deferred (unparsed) quasi-quote: captures a template and its splice arguments without parsing it.
 
Node * __builtin_quote_lazy_n (const char *tmpl, Node **nodes, int count)
 Array-form deferred quasi-quote; see __builtin_quote_lazy.
 
Node * __builtin_node_list (Node **nodes, int count)
 Build a ->next-linked node chain from an array, returning the head. Use the result as the argument to a $@k list splice.
 
Type * __builtin_ast_find_type (const char *name)
 Look up a type by tag name (struct/union/enum).
 
bool __builtin_ast_type_exists (const char *name)
 Check whether a type is currently in scope by name.
 
Type * __builtin_ast_get_type (const char *name)
 Look up a type by name, resolving standard base-type spellings.
 
TypeKind __builtin_ast_type_kind (Type *ty)
 Return the TypeKind tag of a type.
 
int __builtin_ast_type_size (Type *ty)
 Return sizeof(ty) in bytes.
 
int __builtin_ast_type_align (Type *ty)
 Return _Alignof(ty) in bytes.
 
bool __builtin_ast_type_is_unsigned (Type *ty)
 Test whether an integer type is unsigned.
 
bool __builtin_ast_type_is_const (Type *ty)
 Test whether a type is const-qualified.
 
Type * __builtin_ast_type_base (Type *ty)
 Return the element type of a pointer or array.
 
int __builtin_ast_type_array_len (Type *ty)
 Return the fixed length of an array type.
 
Type * __builtin_ast_type_return_type (Type *ty)
 Return the return type of a function type.
 
int __builtin_ast_type_param_count (Type *ty)
 Return the number of declared parameters of a function type.
 
Type * __builtin_ast_type_param_at (Type *ty, int index)
 Return the type of the parameter at the given index.
 
bool __builtin_ast_type_is_variadic (Type *ty)
 Test whether a function type is variadic.
 
const char * __builtin_ast_type_name (Type *ty)
 Return the user-visible name of a type, if any.
 
const char * __builtin_ast_type_c_name (Type *ty)
 Return a valid C identifier fragment naming ty.
 
Type * __builtin_ast_make_pointer (Type *base)
 Build a pointer-to-base type.
 
Type * __builtin_ast_make_array (Type *base, int length)
 Build a fixed-length array type.
 
Type * __builtin_ast_make_func_ptr_type (Type *return_ty, Type **param_types, int nparams)
 Build a pointer-to-function type, e.g. "T (*)(T)".
 
Type * __builtin_ast_make_const (Type *ty)
 Return a const-qualified copy of ty.
 
Type * __builtin_ast_make_volatile (Type *ty)
 Return a volatile-qualified copy of ty.
 
int __builtin_ast_enum_count (Type *enum_type)
 Return the number of constants in an enum type.
 
EnumConstant * __builtin_ast_enum_at (Type *enum_type, int index)
 Return the enum constant at a given index.
 
EnumConstant * __builtin_ast_enum_find (Type *enum_type, const char *name)
 Look up an enum constant by name.
 
const char * __builtin_ast_enum_constant_name (EnumConstant *ec)
 Return the name of an enum constant.
 
int64_t __builtin_ast_enum_constant_value (EnumConstant *ec)
 Return the integer value of an enum constant.
 
const char * __builtin_ast_enum_name (Type *e)
 Return the tag name of an enum type.
 
int __builtin_ast_enum_value_count (Type *e)
 Return the number of values in an enum type.
 
const char * __builtin_ast_enum_value_name (Type *e, int index)
 Return the name of the enum constant at the given index.
 
int64_t __builtin_ast_enum_value (Type *e, int index)
 Return the integer value of the enum constant at the given index.
 
Node * __builtin_ast_enum_to_string_switch (Type *ty, Node *expr)
 Build a switch (expr) { case V0: return "Name0"; ... default: return ""; } over the constants of an enum type.
 
Node * __builtin_ast_enum_from_string_chain (Type *ty, Node *expr)
 Build a block of if (strcmp(expr, "Name0") == 0) return V0; ... return -1; over the constants of an enum type.
 
int __builtin_ast_struct_member_count (Type *struct_type)
 Return the number of members of a struct or union type.
 
Member * __builtin_ast_struct_member_at (Type *struct_type, int index)
 Return the member at the given index.
 
Member * __builtin_ast_struct_member_find (Type *struct_type, const char *name)
 Look up a struct or union member by name.
 
const char * __builtin_ast_member_name (Member *m)
 Return the name of a struct/union member.
 
Type * __builtin_ast_member_type (Member *m)
 Return the type of a struct/union member.
 
int __builtin_ast_member_offset (Member *m)
 Return the byte offset of a struct/union member.
 
bool __builtin_ast_member_is_bitfield (Member *m)
 Test whether a member is a bitfield.
 
int __builtin_ast_member_bitfield_width (Member *m)
 Return the bit width of a bitfield member.
 
int64_t __builtin_ast_offsetof_chain (Type *ty, const char **names, int n)
 Compute the byte offset of a (possibly nested) member chain.
 
Obj * __builtin_ast_find_global (const char *name)
 Look up a global symbol by name.
 
int __builtin_ast_global_count (void)
 Return the total number of global symbols.
 
Obj * __builtin_ast_global_at (int index)
 Return the global symbol at the given index.
 
const char * __builtin_ast_obj_name (Obj *obj)
 Return the name of a global object.
 
Type * __builtin_ast_obj_type (Obj *obj)
 Return the type of a global object.
 
bool __builtin_ast_obj_is_function (Obj *obj)
 Test whether a global object is a function.
 
bool __builtin_ast_obj_is_definition (Obj *obj)
 Test whether a global object has a definition.
 
bool __builtin_ast_obj_is_static (Obj *obj)
 Test whether a global object has internal (static) linkage.
 
Node * __builtin_ast_function_body (Obj *fn)
 Return the top-level block of a function definition.
 
int __builtin_ast_function_param_count (Obj *fn)
 Return the number of parameters of a function definition.
 
Obj * __builtin_ast_function_param_at (Obj *fn, int index)
 Return a parameter of a function definition, in declaration order.
 
int __builtin_ast_function_local_count (Obj *fn)
 Return the number of source-level locals of a function definition.
 
Obj * __builtin_ast_function_local_at (Obj *fn, int index)
 Return a local variable of a function definition, in declaration order.
 
Obj * __builtin_ast_obj_next (Obj *obj)
 Return the next Obj in the list that holds obj.
 
NodeKind __builtin_ast_node_kind (Node *node)
 Return the kind of a node.
 
Type * __builtin_ast_node_type (Node *node)
 Return the resolved type of an expression node.
 
Node * __builtin_ast_node_next (Node *node)
 Return the next node in a statement or argument list.
 
Node * __builtin_ast_node_lhs (Node *node)
 Return the left operand (or sole operand) of a node.
 
Node * __builtin_ast_node_rhs (Node *node)
 Return the right operand of a node.
 
Node * __builtin_ast_node_body (Node *node)
 Return the statement list of an NK_BLOCK or NK_STMT_EXPR.
 
Node * __builtin_ast_node_cond (Node *node)
 Return the condition of an if, loop, switch or ?: node.
 
Node * __builtin_ast_node_then (Node *node)
 Return the then-branch of an if or ?: node, or the body of a loop or switch.
 
Node * __builtin_ast_node_else (Node *node)
 Return the else-branch of an if or ?: node.
 
Node * __builtin_ast_node_init (Node *node)
 Return the initialiser of a for node.
 
Node * __builtin_ast_node_inc (Node *node)
 Return the increment of a for node.
 
int __builtin_ast_block_count (Node *block)
 Return the number of statements in an NK_BLOCK or NK_STMT_EXPR.
 
Node * __builtin_ast_block_at (Node *block, int index)
 Return a statement of an NK_BLOCK or NK_STMT_EXPR.
 
Node * __builtin_ast_call_callee (Node *call)
 Return the callee expression of a call.
 
int __builtin_ast_call_arg_count (Node *call)
 Return the number of arguments of a call.
 
Node * __builtin_ast_call_arg_at (Node *call, int index)
 Return an argument of a call.
 
long long __builtin_ast_node_int_value (Node *node)
 Return the value of an integer NK_NUM literal.
 
double __builtin_ast_node_float_value (Node *node)
 Return the value of a floating NK_NUM literal.
 
Obj * __builtin_ast_node_var_obj (Node *node)
 Return the variable an NK_VAR (or NK_MEMZERO) node refers to.
 
Member * __builtin_ast_node_member (Node *node)
 Return the member an NK_MEMBER node selects.
 
int __builtin_ast_switch_case_count (Node *sw)
 Return the number of case labels of a switch (excluding default).
 
Node * __builtin_ast_switch_case_at (Node *sw, int index)
 Return a case label of a switch, in source order.
 
Node * __builtin_ast_switch_default (Node *sw)
 Return the default label of a switch.
 
long long __builtin_ast_case_begin (Node *node)
 Return the first value of an NK_CASE label.
 
long long __builtin_ast_case_end (Node *node)
 Return the last value of an NK_CASE label (equal to CaseBegin unless a GNU range).
 
Node * __builtin_ast_case_body (Node *node)
 Return the statement that follows an NK_CASE label.
 
const char * __builtin_ast_macro_call_name (Node *node)
 Return the macro name of a not-yet-expanded NK_MACRO_CALL.
 
int __builtin_ast_macro_call_arg_count (Node *node)
 Return the argument count of an NK_MACRO_CALL.
 
Node * __builtin_ast_macro_call_arg_at (Node *node, int index)
 Return an argument of an NK_MACRO_CALL.
 
Node * __builtin_ast_node_strip_implicit (Node *node)
 Peel compiler-inserted casts and call wrappers off a node.
 
const char * __builtin_ast_label_name (Node *node)
 Return the name of an NK_GOTO, NK_LABEL or NK_LABEL_VAL.
 
int __builtin_ast_goto_jump_kind (Node *node)
 Return which statement an NK_GOTO came from.
 
const char * __builtin_ast_asm_template (Node *node)
 Return the template string of an NK_ASM statement.
 
int __builtin_ast_asm_output_count (Node *node)
 Return the number of output operands of an NK_ASM statement.
 
int __builtin_ast_asm_input_count (Node *node)
 Return the number of input operands of an NK_ASM statement.
 
const char * __builtin_ast_asm_operand_constraint (Node *node, int index)
 Return the constraint string of an asm operand.
 
const char * __builtin_ast_asm_operand_name (Node *node, int index)
 Return the symbolic name of an asm operand.
 
Node * __builtin_ast_asm_operand_expr (Node *node, int index)
 Return the expression of an asm operand.
 
int __builtin_ast_asm_clobber_count (Node *node)
 Return the number of clobbers of an NK_ASM statement.
 
const char * __builtin_ast_asm_clobber_at (Node *node, int index)
 Return a clobber of an NK_ASM statement.
 
bool __builtin_ast_asm_is_volatile (Node *node)
 Return whether an NK_ASM statement is written volatile.
 
bool __builtin_ast_asm_is_goto (Node *node)
 Return whether an NK_ASM statement is an asm goto.
 
int __builtin_ast_asm_goto_label_count (Node *node)
 Return the number of jump labels of an asm goto.
 
const char * __builtin_ast_asm_goto_label_at (Node *node, int index)
 Return a jump label name of an asm goto.
 
int __builtin_ast_atomic_order (Node *node)
 Return the memory order of an NK_CAS, NK_EXCH, NK_ALOAD or NK_ASTORE.
 
int __builtin_ast_atomic_fail_order (Node *node)
 Return the failure memory order of an NK_CAS.
 
bool __builtin_ast_atomic_is_weak (Node *node)
 Return whether an NK_CAS was written as a weak compare-exchange.
 
Node * __builtin_ast_cas_addr (Node *node)
 Return the address operand of an NK_CAS.
 
Node * __builtin_ast_cas_expected (Node *node)
 Return the expected-value operand of an NK_CAS.
 
Node * __builtin_ast_cas_desired (Node *node)
 Return the desired-value operand of an NK_CAS.
 
bool __builtin_ast_fence_is_signal (Node *node)
 Return whether an NK_FENCE is a signal fence.
 
int __builtin_ast_bitop_op (Node *node)
 Return the operation of an NK_BITOP.
 
int __builtin_ast_bitop_width (Node *node)
 Return the bit width of an NK_BITOP's builtin.
 
int __builtin_ast_overflow_op (Node *node)
 Return the operation of an NK_OVERFLOW_ARITH.
 
Node * __builtin_ast_overflow_result_ptr (Node *node)
 Return the result pointer of an NK_OVERFLOW_ARITH.
 
int __builtin_attr_target_kind (AttrTarget *target)
 Return the kind of declaration decorated by a custom attribute.
 
const char * __builtin_attr_target_name (AttrTarget *target)
 Return the decorated declaration's source name, when available.
 
Type * __builtin_attr_target_type (AttrTarget *target)
 Return the decorated declaration's type.
 
Obj * __builtin_attr_target_obj (AttrTarget *target)
 Return the decorated function or global object, or NULL for type targets.
 
Token * __builtin_attr_target_token (AttrTarget *target)
 Return a source token for the decorated declaration.
 
Member * __builtin_attr_target_member (AttrTarget *target)
 Return the attributed member of an ATTR_TARGET_MEMBER target, else NULL.
 
Type * __builtin_attr_target_owner (AttrTarget *target)
 Return the struct or union declaring an ATTR_TARGET_MEMBER target's member, or the function type of an ATTR_TARGET_PARAM target, else NULL.
 
Type * __builtin_attr_target_param (AttrTarget *target)
 Return the attributed parameter's type of an ATTR_TARGET_PARAM target, else NULL.
 
int __builtin_attr_target_param_index (AttrTarget *target)
 Return the position of an ATTR_TARGET_PARAM target in its parameter list, else -1.
 
int __builtin_ast_member_has_attr (Member *m, const char *name)
 Return 1 if the member carries the custom attribute name.
 
int __builtin_ast_member_attr_arg_count (Member *m, const char *name)
 Return the argument count of the member's first use of name, or -1 when absent.
 
Node * __builtin_ast_member_attr_arg (Member *m, const char *name, int index)
 Return argument index of the member's first use of name, or NULL.
 
int __builtin_ast_member_attr_count (Member *m)
 Return the number of custom attribute uses on the member.
 
const char * __builtin_ast_member_attr_name_at (Member *m, int index)
 Return the name of the member's attribute use index, or NULL.
 
int __builtin_ast_member_attr_arg_count_at (Member *m, int index)
 Return the argument count of the member's attribute use index, or -1.
 
Node * __builtin_ast_member_attr_arg_at (Member *m, int index, int arg)
 Return argument arg of the member's attribute use index, or NULL.
 
int __builtin_ast_param_has_attr (Type *p, const char *name)
 Return 1 if the parameter type p carries the custom attribute name. p comes from TypeParamAt() on the function type.
 
int __builtin_ast_param_attr_arg_count (Type *p, const char *name)
 Return the argument count of the parameter's first use of name, or -1 when absent.
 
Node * __builtin_ast_param_attr_arg (Type *p, const char *name, int index)
 Return argument index of the parameter's first use of name, or NULL.
 
int __builtin_ast_param_attr_count (Type *p)
 Return the number of custom attribute uses on the parameter.
 
const char * __builtin_ast_param_attr_name_at (Type *p, int index)
 Return the name of the parameter's attribute use index, or NULL.
 
int __builtin_ast_param_attr_arg_count_at (Type *p, int index)
 Return the argument count of the parameter's attribute use index, or -1.
 
Node * __builtin_ast_param_attr_arg_at (Type *p, int index, int arg)
 Return argument arg of the parameter's attribute use index, or NULL.
 
Node * __builtin_ast_int_literal (int64_t value)
 Build an integer literal AST node.
 
Node * __builtin_ast_float_literal (double value)
 Build a floating-point literal AST node.
 
Node * __builtin_ast_string_literal (const char *str)
 Build a string literal AST node.
 
const char * __builtin_ast_string_literal_value (Node *node)
 Return the text of a string literal node.
 
bool __builtin_ast_const_int_value (Node *node, int64_t *out)
 Evaluate an integer constant expression node.
 
bool __builtin_ast_const_uint_value (Node *node, uint64_t *out)
 Evaluate an unsigned integer constant expression node.
 
Node * __builtin_ast_var_ref (const char *name)
 Build a variable reference AST node.
 
Node * __builtin_ast_param_ref (Obj *fn, const char *name)
 Build a reference to a function parameter by name.
 
Node * __builtin_ast_binary (NodeKind op, Node *left, Node *right)
 Build a binary operation AST node.
 
Node * __builtin_ast_unary (NodeKind op, Node *operand)
 Build a unary operation AST node.
 
Node * __builtin_ast_cast (Node *expr, Type *target_type)
 Build a type cast AST node.
 
Node * __builtin_ast_cond (Node *cond, Node *then_expr, Node *else_expr)
 Build a ternary conditional expression node (cond ? then : else).
 
Node * __builtin_ast_null (void)
 Build a typed null pointer node: (void *)0.
 
Node * __builtin_ast_sizeof_type (Type *ty)
 Emit sizeof(ty) as a compile-time integer literal.
 
Node * __builtin_ast_alignof_type (Type *ty)
 Emit _Alignof(ty) as a compile-time integer literal.
 
Node * __builtin_ast_sizeof_expr (Node *expr)
 Emit sizeof(expr): resolve the expression's type then its size.
 
Node * __builtin_ast_subscript (Node *arr, Node *idx)
 Build an array subscript node: arr[idx], desugared as *(arr+idx).
 
Node * __builtin_ast_comma (Node *lhs, Node *rhs)
 Build a comma expression: evaluate lhs, yield rhs.
 
Node * __builtin_ast_return (Node *expr)
 Build a return statement node.
 
Node * __builtin_ast_block (Node **stmts, int count)
 Build a block (compound statement) node.
 
Node * __builtin_ast_block_add_stmt (Node *block, Node *stmt)
 Append a statement to a block node.
 
Node * __builtin_ast_if (Node *cond, Node *then_body, Node *else_body)
 Build an if statement node.
 
Node * __builtin_ast_switch (Node *cond)
 Build a switch statement node.
 
void __builtin_ast_switch_add_case (Node *switch_node, Node *value, Node *body)
 Append a case to a switch statement.
 
void __builtin_ast_switch_set_default (Node *switch_node, Node *body)
 Set the default case for a switch statement.
 
Node * __builtin_ast_expr_stmt (Node *expr)
 Build an expression statement node.
 
Node * __builtin_ast_local_var (const char *name, Type *ty)
 Declare a named local variable in the current function scope and return a variable-reference node for it.
 
Node * __builtin_ast_local_var_unique (Type *ty)
 Declare a hygienic (gensym'd) local variable in the current function scope and return a variable-reference node for it.
 
Node * __builtin_ast_assign (Node *target, Node *value)
 Build an assignment node (target = value).
 
Node * __builtin_ast_member (Node *obj, const char *name)
 Create a struct/union member access node (obj.name).
 
Node * __builtin_ast_funcall (Node *callee, Node **args, int n)
 Create a function call node.
 
Node * __builtin_ast_while (Node *cond, Node *body)
 Create a while loop node.
 
Node * __builtin_ast_for (Node *init, Node *cond, Node *inc, Node *body)
 Create a for loop node.
 
Node * __builtin_ast_do_while (Node *body, Node *cond)
 Create a do-while loop node.
 
void __builtin_ast_push_loop (Node *loop)
 Establish loop as the current loop context, so an eagerly-parsed Quote("break;")/Quote("continue;") call made while it is active resolves against loop's own break/continue targets.
 
void __builtin_ast_pop_loop (void)
 Restore the loop context saved by the most recent push.
 
Node * __builtin_ast_loop_set_body (Node *loop, Node *body)
 Attach body to loop (a node from MakeWhile/MakeFor/MakeDoWhile).
 
Obj * __builtin_ast_function (const char *name, Type *return_type)
 Create a new function object.
 
Node * __builtin_ast_publish (Obj *obj, Token *tok)
 Make a generated object visible at the current source position.
 
Node * __builtin_ast_publish_type (Type *ty, Token *tok)
 Accept a generated type declaration as already published.
 
void __builtin_emit_directive (const char *line)
 Emit one raw preprocessor directive line into generated output.
 
void __builtin_ast_function_add_param (Obj *fn, const char *name, Type *type)
 Add a parameter to a function.
 
void __builtin_ast_function_set_body (Obj *fn, Node *body)
 Set the body of a function.
 
void __builtin_ast_function_set_static (Obj *fn, bool is_static)
 Set whether a function has static linkage.
 
void __builtin_ast_function_set_inline (Obj *fn, bool is_inline)
 Set whether a function is inline.
 
void __builtin_ast_function_set_variadic (Obj *fn, bool is_variadic)
 Set whether a function is variadic.
 
Obj * __builtin_ast_function_prototype (const char *name, Type *return_type)
 Create a function forward declaration (prototype) without a body.
 
void __builtin_ast_add_attribute (Obj *fn, const char *attr_text)
 Apply an attribute string to a programmatically created function.
 
void __builtin_ast_add_build_target_attr (Obj *fn, const char *kind)
 
Type * __builtin_ast_make_struct (const char *name)
 Create and expose a new named struct type.
 
Type * __builtin_ast_make_union (const char *name)
 Create and expose a new named union type.
 
Type * __builtin_ast_struct_add_field (Type *ty, const char *name, Type *field_type)
 Append a field to a struct or union and recompute its layout.
 
Type * __builtin_ast_make_enum (const char *name)
 Create and expose a new named enum type.
 
void __builtin_ast_enum_add_constant (Type *ty, const char *name, int64_t value)
 Add a named constant to an enum type and expose it in scope.
 
Type * __builtin_ast_make_typedef (const char *name, Type *underlying)
 Register a typedef alias for a type and expose it in scope.
 
Obj * __builtin_ast_global_var (const char *name, Type *ty)
 Create a new named global variable definition.
 
void __builtin_ast_global_var_set_init_data (Obj *var, const char *data, int len)
 Set the initial data for a generated global variable.
 
void __builtin_ast_global_var_set_static (Obj *var, bool is_static)
 Set the static (internal linkage) flag on a generated global.
 
void __builtin_ast_push_fn (Obj *fn)
 Establish fn as the "function currently being built" so that Quote("return x;") applies the correct implicit return-type cast.
 
void __builtin_ast_pop_fn (void)
 Restore the function context saved by the most recent push.
 
void __builtin_ast_push_block (Node *block)
 Establish a block as the current statement-append context.
 
void __builtin_ast_pop_block (void)
 
Node * __builtin_ast_block_add_current_stmt (Node *stmt)
 
void __builtin_ast_push_struct (Type *ty)
 Establish a struct or union as the current field-add context.
 
void __builtin_ast_pop_struct (void)
 
Type * __builtin_ast_struct_add_current_field (const char *name, Type *field_type)
 
void __builtin_ast_push_switch (Node *switch_node)
 Establish a switch node as the current case/default context.
 
void __builtin_ast_pop_switch (void)
 
void __builtin_ast_switch_add_current_case (Node *value, Node *body)
 
void __builtin_ast_switch_set_current_default (Node *body)
 
void __builtin_ast_push_enum (Type *ty)
 Establish an enum as the current constant-add context.
 
void __builtin_ast_pop_enum (void)
 
void __builtin_ast_enum_add_current_constant (const char *name, int value)
 
void __builtin_dump_tree (Node *node)
 Print a human-readable tree representation of a node to stdout.
 
const char * __builtin_dump_tree_to_string (Node *node)
 Render the tree representation to a heap-allocated string.
 
void __builtin_dump_ast_gen (Node *node)
 Print __builtin_ast_*() builder calls that would reconstruct the node.
 
const char * __builtin_dump_ast_gen_to_string (Node *node)
 Render the __builtin_ast_*() builder call sequence to a string.
 
int64_t __builtin_get_comptime_int (const char *name)
 Read an integer-typed #pragma comptime variable's value at compile time.
 
double __builtin_get_comptime_float (const char *name)
 Read a float/double-typed #pragma comptime variable's value at compile time.
 
Node * __builtin_get_comptime_var (const char *name)
 Read a comptime scalar variable as an AST literal node.
 
Node * __builtin_get_comptime_ptr (const char *name)
 Return the address of a comptime variable as a generated-code AST pointer node.
 
Node * __builtin_get_comptime_member (const char *var_name, const char *field)
 Read a named field from a comptime struct variable as an AST literal node.
 
Node * __builtin_get_constexpr_value (const char *name)
 Read the evaluated initializer of a global constexpr variable as an AST literal node.
 
Node * __builtin_ast_compound_literal (Type *ty, Node **inits, int n)
 Build a positional compound literal: zero-initialise an anonymous local var then positionally assign inits via node_expand_init_splice.
 
Node * __builtin_ast_init_array (Type *elem_ty, Node **elems, int n)
 Build an array compound literal. Element type is explicit to avoid long-inference surprises with MakeIntLiteral.
 
Node * __builtin_ast_init_struct (Type *ty, const char **fields, Node **values, int n)
 Build a designated struct/union initializer. Unmentioned fields are zero-initialised. Partial init (n < member count) is allowed.
 
Node * __builtin_ast_serialize (Type *ty, Node *expr, Node *buf)
 Build a block of memcpy() calls copying expr (of type ty) into buf (a void or char pointer). Struct/union types are copied member-by-member at their natural offsets, recursing into nested structs; bit-fields copy the bytes holding their bits; scalar types are copied in one memcpy. buf needs no particular alignment.
 
Node * __builtin_ast_deserialize (Type *ty, Node *buf)
 Build an expression that reconstructs a ty value from buf, copying each member out of the buffer into a zeroed hidden local (the mirror of Serialize). buf needs no particular alignment.
 
void __builtin_generate_sum (Type *elem_ty)
 Publish T sum_T(T *arr, size_t n) summing all elements.
 
void __builtin_generate_map (Type *elem_ty)
 Publish void map_T(T *arr, size_t n, T *out, T (*f)(T)), writing f(arr[i]) into out[i] for each element.
 
void __builtin_generate_reduce (Type *elem_ty)
 Publish T reduce_T(T *arr, size_t n, T init, T (*f)(T, T)), folding f over the array starting from init.
 
void __builtin_generate_filter (Type *elem_ty)
 Publish void filter_T(T *arr, size_t n, T *out, size_t *out_n, bool (*pred)(T)), writing elements matching pred into out and setting *out_n to the match count.
 

Detailed Description

Reflection and AST Construction API for CCCC Comptime Functions.

This header provides APIs for:

Return-value model

A comptime function's returned Node* is the node spliced at the call site, replacing the invocation. Top-level definitions (functions, globals) are side effects — injected into the program regardless of the return value.

Declare a definition-only function with a void return type for clarity:

[[cccc::comptime]]
void emit_helpers(void) {
Obj *fn = MakeFunction("helper", GetType("int"));
WithFn(fn) {
FunctionSetBody(fn, Quote("return 42;"));
}
// no return needed
}
emit_helpers();
#define MakeFunction(name, ret_type)
Create a new function object, automatically added to the globals list.
Definition reflection.h:3148
#define WithFn(fn)
Block helper: establishes fn as the current function-building context so Quote("return x;") applies t...
Definition reflection.h:3521
#define PublishNode(decl)
Make a generated declaration visible at the current source position.
Definition reflection.h:3154
#define Quote(tmpl,...)
Parse a C code template string into an AST node, substituting $N / $@N splice points with the given a...
Definition reflection.h:2144
#define GetType(name)
Look up a type by name, resolving any standard base-type spelling ("unsigned char",...
Definition reflection.h:2292
#define FunctionSetBody(fn, body)
Set the body of a function.
Definition reflection.h:3189

A void comptime function used in expression position is a compile error.

Usage

This private header is embedded into CCCC and automatically injected when compiling comptime functions. It is not installed as a public runtime header. Functions that need VM context read it internally from a process-global set by the compiler for the duration of macro execution – macro authors never see or pass a VM object.

Example (expression comptime function)

[[cccc::comptime]]
Node *make_const_5(void) {
return MakeIntLiteral(5);
}
int main(void) {
int x = make_const_5(); // x == 5
return 0;
}
#define MakeIntLiteral(val)
Build an integer literal AST node.
Definition reflection.h:2353

Macro Definition Documentation

◆ __builtin_block_add_stmt_1

#define __builtin_block_add_stmt_1 (   stmt,
  _ignored 
)     __builtin_ast_block_add_current_stmt(stmt)

◆ __builtin_block_add_stmt_2

#define __builtin_block_add_stmt_2 (   block,
  stmt 
)     __builtin_ast_block_add_stmt(block, stmt)

◆ __builtin_dispatch_2

#define __builtin_dispatch_2 (   _1,
  _2,
  which,
  ... 
)    which(_1, _2)

◆ __builtin_dispatch_3

#define __builtin_dispatch_3 (   _1,
  _2,
  _3,
  which,
  ... 
)    which(_1, _2, _3)

◆ __builtin_enum_add_constant_2

#define __builtin_enum_add_constant_2 (   name,
  value,
  _ignored 
)     __builtin_ast_enum_add_current_constant(name, value)

◆ __builtin_enum_add_constant_3

#define __builtin_enum_add_constant_3 (   ty,
  name,
  value 
)     __builtin_ast_enum_add_constant(ty, name, value)

◆ __builtin_foreach_member_body

#define __builtin_foreach_member_body (   type,
  varname,
  body,
  uid 
)
Value:
do { \
Type *__builtin_fem_ty_##uid = (type); \
int __builtin_fem_n_##uid = StructMemberCount(__builtin_fem_ty_##uid); \
for (int __builtin_fem_i_##uid = 0; \
__builtin_fem_i_##uid < __builtin_fem_n_##uid; \
__builtin_fem_i_##uid++) { \
Member *varname = \
StructMemberAt(__builtin_fem_ty_##uid, __builtin_fem_i_##uid); \
body \
} \
} while (0)
#define StructMemberCount(ty)
Return the number of members of a struct or union type.
Definition reflection.h:2681

◆ __builtin_foreach_member_uid

#define __builtin_foreach_member_uid (   type,
  varname,
  body,
  uid 
)     __builtin_foreach_member_body(type, varname, body, uid)

◆ __builtin_struct_add_field_2

#define __builtin_struct_add_field_2 (   name,
  field_type,
  _ignored 
)     __builtin_ast_struct_add_current_field(name, field_type)

◆ __builtin_struct_add_field_3

#define __builtin_struct_add_field_3 (   ty,
  name,
  field_type 
)     __builtin_ast_struct_add_field(ty, name, field_type)

◆ __builtin_switch_add_case_2

#define __builtin_switch_add_case_2 (   v,
  b,
  _ignored 
)     __builtin_ast_switch_add_current_case(v, b)

◆ __builtin_switch_add_case_3

#define __builtin_switch_add_case_3 (   sw,
  v,
  b 
)     __builtin_ast_switch_add_case(sw, v, b)

◆ __builtin_switch_set_default_1

#define __builtin_switch_set_default_1 (   b,
  _ignored 
)     __builtin_ast_switch_set_current_default(b)

◆ __builtin_switch_set_default_2

#define __builtin_switch_set_default_2 (   sw,
  b 
)     __builtin_ast_switch_set_default(sw, b)

◆ __CCCC_TAG

#define __CCCC_TAG (   n)    __cccc_##n

◆ AddAttribute

#define AddAttribute (   fn,
  text 
)    __builtin_ast_add_attribute(fn, text)

Apply an attribute string to a programmatically created function.

Parameters
fnThe function object to attribute (created by MakeFunction).
textAttribute text as it would appear between [[ and ]], e.g. "cccc::test", "nodiscard", or "@myattr".

◆ AsmClobberAt

#define AsmClobberAt (   node,
  i 
)    __builtin_ast_asm_clobber_at(node, i)

Return a clobber of an NK_ASM statement.

Parameters
nodeAn NK_ASM node.
iZero-based clobber index.

◆ AsmClobberCount

#define AsmClobberCount (   node)    __builtin_ast_asm_clobber_count(node)

Return the number of clobbers of an NK_ASM statement.

Parameters
nodeAn NK_ASM node.

◆ AsmGotoLabelAt

#define AsmGotoLabelAt (   node,
  i 
)    __builtin_ast_asm_goto_label_at(node, i)

Return a jump label name of an asm goto.

Parameters
nodeAn NK_ASM node.
iZero-based label index.

◆ AsmGotoLabelCount

#define AsmGotoLabelCount (   node)    __builtin_ast_asm_goto_label_count(node)

Return the number of jump labels of an asm goto.

Parameters
nodeAn NK_ASM node.

◆ AsmInputCount

#define AsmInputCount (   node)    __builtin_ast_asm_input_count(node)

Return the number of input operands of an NK_ASM statement.

Parameters
nodeAn NK_ASM node.

◆ AsmIsGoto

#define AsmIsGoto (   node)    __builtin_ast_asm_is_goto(node)

Return whether an NK_ASM statement is an asm goto.

Parameters
nodeAn NK_ASM node.

◆ AsmIsVolatile

#define AsmIsVolatile (   node)    __builtin_ast_asm_is_volatile(node)

Return whether an NK_ASM statement is written volatile.

Parameters
nodeAn NK_ASM node.

◆ AsmOperandConstraint

#define AsmOperandConstraint (   node,
  i 
)     __builtin_ast_asm_operand_constraint(node, i)

Return the constraint string of an asm operand.

Parameters
nodeAn NK_ASM node.
iZero-based operand index; outputs come before inputs.

◆ AsmOperandExpr

#define AsmOperandExpr (   node,
  i 
)    __builtin_ast_asm_operand_expr(node, i)

Return the expression of an asm operand.

Parameters
nodeAn NK_ASM node.
iZero-based operand index; outputs come before inputs.

◆ AsmOperandName

#define AsmOperandName (   node,
  i 
)    __builtin_ast_asm_operand_name(node, i)

Return the symbolic name of an asm operand, or NULL.

Parameters
nodeAn NK_ASM node.
iZero-based operand index; outputs come before inputs.

◆ AsmOutputCount

#define AsmOutputCount (   node)    __builtin_ast_asm_output_count(node)

Return the number of output operands of an NK_ASM statement.

Parameters
nodeAn NK_ASM node.

◆ AsmTemplate

#define AsmTemplate (   node)    __builtin_ast_asm_template(node)

Return the template string of an NK_ASM statement.

Parameters
nodeAn NK_ASM node.

◆ AtomicFailOrder

#define AtomicFailOrder (   node)    __builtin_ast_atomic_fail_order(node)

Return the failure memory order of an NK_CAS, -1 for other kinds.

Parameters
nodeAn NK_CAS node.

◆ AtomicIsWeak

#define AtomicIsWeak (   node)    __builtin_ast_atomic_is_weak(node)

Return whether an NK_CAS was written as a weak compare-exchange.

Parameters
nodeAn NK_CAS node.

◆ AtomicOrder

#define AtomicOrder (   node)    __builtin_ast_atomic_order(node)

Return the __ATOMIC_* memory order of an atomic node, -1 for other kinds.

Parameters
nodeAn NK_CAS, NK_EXCH, NK_ALOAD or NK_ASTORE node.

◆ AttrTargetMember

#define AttrTargetMember (   target)    __builtin_attr_target_member(target)

Return the attributed member of an ATTR_TARGET_MEMBER target.

Parameters
targetThe attribute target to inspect.

◆ AttrTargetName

#define AttrTargetName (   target)    __builtin_attr_target_name(target)

Return the decorated declaration's source name, when available.

Parameters
targetThe attribute target to inspect.

◆ AttrTargetObj

#define AttrTargetObj (   target)    __builtin_attr_target_obj(target)

Return the decorated function or global object, or NULL for type targets.

Parameters
targetThe attribute target to inspect.

◆ AttrTargetOwner

#define AttrTargetOwner (   target)    __builtin_attr_target_owner(target)

Return the struct or union declaring an ATTR_TARGET_MEMBER target's member, or the function type of an ATTR_TARGET_PARAM target.

Parameters
targetThe attribute target to inspect.

◆ AttrTargetParam

#define AttrTargetParam (   target)    __builtin_attr_target_param(target)

Return the attributed parameter's type of an ATTR_TARGET_PARAM target.

Parameters
targetThe attribute target to inspect.

◆ AttrTargetParamIndex

#define AttrTargetParamIndex (   target)    __builtin_attr_target_param_index(target)

Return the position of an ATTR_TARGET_PARAM target in its parameter list, or -1.

Parameters
targetThe attribute target to inspect.

◆ AttrTargetToken

#define AttrTargetToken (   target)    __builtin_attr_target_token(target)

Return a source token for the decorated declaration.

Parameters
targetThe attribute target to inspect.

◆ AttrTargetType

#define AttrTargetType (   target)    __builtin_attr_target_type(target)

Return the decorated declaration's type.

Parameters
targetThe attribute target to inspect.

◆ BitopOp

#define BitopOp (   node)    __builtin_ast_bitop_op(node)

Return the operation (AST_BITOP_*) of an NK_BITOP.

Parameters
nodeAn NK_BITOP node.

◆ BitopWidth

#define BitopWidth (   node)    __builtin_ast_bitop_width(node)

Return the bit width of an NK_BITOP's builtin.

Parameters
nodeAn NK_BITOP node.

◆ BlockAddStmt

#define BlockAddStmt (   ...)
Value:
#define __builtin_block_add_stmt_2(block, stmt)
Definition reflection.h:2457
#define __builtin_dispatch_2(_1, _2, which,...)
Definition reflection.h:2248
#define __builtin_block_add_stmt_1(stmt, _ignored)
Definition reflection.h:2455

Append a statement to a block.

Parameters
...Either (stmt) inside a WithBlock(block) block, or (block, stmt) to name the block explicitly.

Dispatches on argument count via __builtin_dispatch_2.

◆ BlockAt

#define BlockAt (   block,
  i 
)    __builtin_ast_block_at(block, i)

Return a statement of an NK_BLOCK or NK_STMT_EXPR.

Parameters
blockThe block node.
iZero-based statement index.

◆ BlockCount

#define BlockCount (   block)    __builtin_ast_block_count(block)

Return the number of statements in an NK_BLOCK or NK_STMT_EXPR.

Parameters
blockThe block node.

◆ CallArgAt

#define CallArgAt (   call,
  i 
)    __builtin_ast_call_arg_at(call, i)

Return an argument of a call.

Parameters
callAn NK_FUNCALL node (or the comma wrapper around one).
iZero-based argument index.

◆ CallArgCount

#define CallArgCount (   call)    __builtin_ast_call_arg_count(call)

Return the number of arguments of a call.

Parameters
callAn NK_FUNCALL node (or the comma wrapper around one).

◆ CallCallee

#define CallCallee (   call)    __builtin_ast_call_callee(call)

Return the callee expression of a call.

Parameters
callAn NK_FUNCALL node (or the comma wrapper around one).

◆ CasAddr

#define CasAddr (   node)    __builtin_ast_cas_addr(node)

Return the address operand of an NK_CAS.

Parameters
nodeAn NK_CAS node.

◆ CasDesired

#define CasDesired (   node)    __builtin_ast_cas_desired(node)

Return the desired-value operand of an NK_CAS.

Parameters
nodeAn NK_CAS node.

◆ CaseBegin

#define CaseBegin (   node)    __builtin_ast_case_begin(node)

Return the first value of an NK_CASE label.

Parameters
nodeAn NK_CASE node.

◆ CaseBody

#define CaseBody (   node)    __builtin_ast_case_body(node)

Return the statement that follows an NK_CASE label.

Parameters
nodeAn NK_CASE node.

◆ CaseEnd

#define CaseEnd (   node)    __builtin_ast_case_end(node)

Return the last value of an NK_CASE label (equal to CaseBegin unless a GNU range).

Parameters
nodeAn NK_CASE node.

◆ CasExpected

#define CasExpected (   node)    __builtin_ast_cas_expected(node)

Return the expected-value operand of an NK_CAS.

Parameters
nodeAn NK_CAS node.

◆ CompoundLiteral

#define CompoundLiteral (   ty,
  ... 
)
Value:
ty, (Node *[]){__VA_ARGS__}, \
(int)(sizeof((Node *[]){__VA_ARGS__}) / sizeof(Node *)))
Node * __builtin_ast_compound_literal(Type *ty, Node **inits, int n)
Build a positional compound literal: zero-initialise an anonymous local var then positionally assign ...

Build a positional compound literal; element count is inferred from the argument list.

Positional compound literal — element count inferred from VA_ARGS.

Parameters
tyThe compound literal's type.
...Node* initializer values, assigned positionally.

Requires function scope (file-scope is not supported).

◆ ConstIntValue

#define ConstIntValue (   node,
  out 
)    __builtin_ast_const_int_value(node, out)

Evaluate an integer constant expression node; false if it is not one.

Parameters
nodeA node, typically a macro or attribute argument.
outAn int64_t * that receives the value.

◆ ConstUIntValue

#define ConstUIntValue (   node,
  out 
)    __builtin_ast_const_uint_value(node, out)

Like ConstIntValue, for a non-negative or unsigned value up to UINT64_MAX; false for a negative signed value.

Parameters
nodeA node, typically a macro or attribute argument.
outA uint64_t * that receives the value.

◆ CopyLocation

#define CopyLocation (   dst,
  src 
)    __builtin_ast_copy_location(dst, src)

Copy the source token from src to dst.

Parameters
dstGenerated node to update.
srcSource node whose location should be reused.

◆ CopyNode

#define CopyNode (   n)    __builtin_ast_copy_node(n)

Deep-copy an expression or simple statement so it can be linked into a second list.

Parameters
nNode to copy.

◆ CurrentToken

#define CurrentToken ( )    __builtin_ast_current_token()

Return the token for the macro invocation currently being executed.

◆ Deserialize

#define Deserialize (   ty,
  buf 
)    __builtin_ast_deserialize(ty, buf)

Build an expression that reconstructs a ty value from buf.

Parameters
tyThe type to reconstruct.
bufThe source buffer, laid out as Serialize writes it.

Padding in the result is zero and buf needs no particular alignment.

◆ DumpAstGen

#define DumpAstGen (   node)    __builtin_dump_ast_gen(node)

Print __builtin_ast_*() builder calls that would reconstruct node.

Parameters
nodeThe root node to emit builder calls for.

◆ DumpAstGenToString

#define DumpAstGenToString (   node)    __builtin_dump_ast_gen_to_string(node)

Render the __builtin_ast_*() builder call sequence for node to a string.

Parameters
nodeThe root node.

◆ DumpTree

#define DumpTree (   node)    __builtin_dump_tree(node)

Print a human-readable tree representation of node to stdout.

Parameters
nodeThe root node to print.

◆ DumpTreeToString

#define DumpTreeToString (   node)    __builtin_dump_tree_to_string(node)

Render the tree representation of node to a heap-allocated string.

Parameters
nodeThe root node.

◆ EmitDirective

#define EmitDirective (   line)    __builtin_emit_directive(line)

Emit one raw preprocessor directive line into generated output.

Parameters
lineComplete directive text, for example "#ifdef _WIN32".

◆ EnumAddConstant

#define EnumAddConstant (   ...)
Value:
#define __builtin_dispatch_3(_1, _2, _3, which,...)
Definition reflection.h:2249
#define __builtin_enum_add_constant_2(name, value, _ignored)
Definition reflection.h:3283
#define __builtin_enum_add_constant_3(ty, name, value)
Definition reflection.h:3285

Add a named constant to an enum type and expose it in scope.

Parameters
...Either (name, value) inside a WithEnum(ty) block, or (ty, name, value) to name the type explicitly.

Dispatches on argument count via __builtin_dispatch_3.

◆ EnumAt

#define EnumAt (   ty,
  i 
)    __builtin_ast_enum_at(ty, i)

Return the enum constant at a given index.

Parameters
tyThe enum type to inspect.
iZero-based index.

◆ EnumConstantName

#define EnumConstantName (   ec)    __builtin_ast_enum_constant_name(ec)

Return the name of an enum constant.

Parameters
ecThe enum constant.

◆ EnumConstantValue

#define EnumConstantValue (   ec)    __builtin_ast_enum_constant_value(ec)

Return the integer value of an enum constant.

Parameters
ecThe enum constant.

◆ EnumCount

#define EnumCount (   ty)    __builtin_ast_enum_count(ty)

Return the number of constants in an enum type.

Parameters
tyThe enum type to inspect.

◆ EnumFind

#define EnumFind (   ty,
  name 
)    __builtin_ast_enum_find(ty, name)

Look up an enum constant by name.

Parameters
tyThe enum type to search.
nameThe constant name to look up.

◆ EnumFromString

#define EnumFromString (   ty,
  expr 
)    __builtin_ast_enum_from_string_chain(ty, expr)

Build an if-chain comparing expr against each constant's name, returning the matching value.

Parameters
tyThe enum type.
exprThe expression to compare (a const char *).

Wrap the result in a function returning the enum type (or an int).

◆ EnumName

#define EnumName (   ty)    __builtin_ast_enum_name(ty)

Return the tag name of an enum type.

Parameters
tyThe enum type to inspect.

◆ EnumToString

#define EnumToString (   ty,
  expr 
)    __builtin_ast_enum_to_string_switch(ty, expr)

Build a switch over ty's constants returning each constant's name as a string.

Parameters
tyThe enum type.
exprThe expression to switch on (the enum value).

Wrap the result in a function returning const char *.

◆ EnumValue

#define EnumValue (   ty,
  i 
)    __builtin_ast_enum_value(ty, i)

Return the integer value of the enum constant at the given index.

Parameters
tyThe enum type to inspect.
iZero-based index.

◆ EnumValueCount

#define EnumValueCount (   ty)    __builtin_ast_enum_value_count(ty)

Return the number of values in an enum type.

Parameters
tyThe enum type to inspect.

◆ EnumValueName

#define EnumValueName (   ty,
  i 
)    __builtin_ast_enum_value_name(ty, i)

Return the name of the enum constant at the given index.

Parameters
tyThe enum type to inspect.
iZero-based index.

◆ FenceIsSignal

#define FenceIsSignal (   node)    __builtin_ast_fence_is_signal(node)

Return whether an NK_FENCE is a signal fence.

Parameters
nodeAn NK_FENCE node.

◆ FindGlobal

#define FindGlobal (   name)    __builtin_ast_find_global(name)

Look up a global symbol by name.

Parameters
nameThe global name to look up.

◆ FindType

#define FindType (   name)    __builtin_ast_find_type(name)

Look up a type by tag name (struct/union/enum).

Parameters
nameThe tag name to look up.

◆ FnBody

#define FnBody (   fn)    __builtin_ast_function_body(fn)

Return the top-level block of a function definition.

Parameters
fnA function Obj.

◆ FnLocalAt

#define FnLocalAt (   fn,
  i 
)    __builtin_ast_function_local_at(fn, i)

Return a local variable of a function definition, in declaration order.

Parameters
fnA function Obj.
iZero-based local index.

◆ FnLocalCount

#define FnLocalCount (   fn)    __builtin_ast_function_local_count(fn)

Return the number of source-level locals of a function definition.

Parameters
fnA function Obj.

◆ FnParamAt

#define FnParamAt (   fn,
  i 
)    __builtin_ast_function_param_at(fn, i)

Return a parameter of a function definition, in declaration order.

Parameters
fnA function Obj.
iZero-based parameter index.

◆ FnParamCount

#define FnParamCount (   fn)    __builtin_ast_function_param_count(fn)

Return the number of parameters of a function definition.

Parameters
fnA function Obj.

◆ ForeachMember

#define ForeachMember (   type,
  varname,
  body 
)     __builtin_foreach_member_uid(type, varname, body, __COUNTER__)

Host-side loop over the members of a struct/union type, evaluated at macro-execution (compile) time.

Parameters
typeThe struct/union Type* to iterate.
varnameIdentifier bound to each Member* in turn.
bodyCompound statement run once per member (typically builds AST nodes via BlockAddStmt etc.).

Nestable: a two-layer COUNTER indirection gives each call site unique loop-variable names.

◆ FunctionAddParam

#define FunctionAddParam (   fn,
  name,
  type 
)     __builtin_ast_function_add_param(fn, name, type)

Add a parameter to a function.

Parameters
fnThe function object.
nameThe parameter name.
typeThe parameter type.

Call once per parameter, in order.

◆ FunctionPrototype

#define FunctionPrototype (   name,
  ret 
)    __builtin_ast_function_prototype(name, ret)

Create a function forward declaration (prototype) without a body.

Parameters
nameThe function name.
retThe return type.

Use FunctionAddParam for parameters and PublishNode to expose it in scope. A published prototype that never receives a body via FunctionSetBody still appears in -c=generated/-m output as a bare declaration.

◆ FunctionSetBody

#define FunctionSetBody (   fn,
  body 
)    __builtin_ast_function_set_body(fn, body)

Set the body of a function.

Parameters
fnThe function object.
bodyThe function body (a statement or block node).

Any local declared while building body — e.g. int x = 1; inside a Quote() template, or a var created by MakeLocalVar / MakeCompoundLiteral — is attached to fn, whether or not this call happens inside a WithFn(fn) block. WithFn is still required to give Quote("return x;") the function's return type for its implicit cast, and to target MakeLocalVar at fn from outside a template.

◆ FunctionSetInline

#define FunctionSetInline (   fn,
  is_inline 
)     __builtin_ast_function_set_inline(fn, is_inline)

Set whether a function is inline.

Parameters
fnThe function object.
is_inlineTrue for inline, false otherwise.

◆ FunctionSetStatic

#define FunctionSetStatic (   fn,
  is_static 
)     __builtin_ast_function_set_static(fn, is_static)

Set whether a function has static linkage.

Parameters
fnThe function object.
is_staticTrue for static linkage, false for external.

◆ FunctionSetVariadic

#define FunctionSetVariadic (   fn,
  is_variadic 
)     __builtin_ast_function_set_variadic(fn, is_variadic)

Set whether a function is variadic.

Parameters
fnThe function object.
is_variadicTrue for variadic, false otherwise.

◆ GenerateFilter

#define GenerateFilter (   elem_type)    __builtin_generate_filter(elem_type)

Publish void filter_T(T *arr, size_t n, T *out, size_t *out_n, bool (*pred)(T)).

Parameters
elem_typeThe element type T.

◆ GenerateMap

#define GenerateMap (   elem_type)    __builtin_generate_map(elem_type)

Publish void map_T(T *arr, size_t n, T *out, T (*f)(T)).

Parameters
elem_typeThe element type T.

◆ GenerateReduce

#define GenerateReduce (   elem_type)    __builtin_generate_reduce(elem_type)

Publish T reduce_T(T *arr, size_t n, T init, T (*f)(T, T)).

Parameters
elem_typeThe element type T.

◆ GenerateSum

#define GenerateSum (   elem_type)    __builtin_generate_sum(elem_type)

Publish T sum_T(T *arr, size_t n) summing all elements.

Parameters
elem_typeThe element type T.

◆ Gensym

#define Gensym (   prefix)    __builtin_gensym(prefix)

Generate a unique identifier string for macro-created symbols.

Parameters
prefixPrefix for the generated name.

◆ GetAttrTargetKind

#define GetAttrTargetKind (   target)    __builtin_attr_target_kind(target)

Return the kind of declaration decorated by a custom attribute.

Parameters
targetThe attribute target to inspect.

◆ GetComptimeFloat

#define GetComptimeFloat (   name)    __builtin_get_comptime_float(name)

Read a float/double-typed #pragma comptime variable's value at compile time.

Parameters
nameThe comptime variable's name.

◆ GetComptimeInt

#define GetComptimeInt (   name)    __builtin_get_comptime_int(name)

Read an integer-typed #pragma comptime variable's value at compile time.

Parameters
nameThe comptime variable's name.

◆ GetComptimeMember

#define GetComptimeMember (   var,
  field 
)    __builtin_get_comptime_member(var, field)

Read a named field from a comptime struct variable as an AST literal node.

Parameters
varThe comptime struct variable's name.
fieldThe field name to look up.

◆ GetComptimePtr

#define GetComptimePtr (   name)    __builtin_get_comptime_ptr(name)

Return the address of a comptime variable as a generated-code AST pointer node.

Parameters
nameThe comptime variable's name.

◆ GetComptimeVar

#define GetComptimeVar (   name)    __builtin_get_comptime_var(name)

Read a comptime scalar variable as an AST literal node.

Parameters
nameThe comptime variable's name.

◆ GetConstexprValue

#define GetConstexprValue (   name)    __builtin_get_constexpr_value(name)

Read the evaluated initializer of a global constexpr variable as an AST literal node.

Parameters
nameThe constexpr variable's name.

Errors at compile time if name does not refer to a visible constexpr variable.

◆ GetNodeKind

#define GetNodeKind (   node)    __builtin_ast_node_kind(node)

Return the kind of a node.

Parameters
nodeThe node to inspect.

◆ GetNodeType

#define GetNodeType (   node)    __builtin_ast_node_type(node)

Return the resolved type of an expression node.

Parameters
nodeThe node to inspect.

◆ GetType

#define GetType (   name)    __builtin_ast_get_type(name)

Look up a type by name, resolving any standard base-type spelling ("unsigned char", "long long", ...); an unresolved name is a hard comptime error. Use FindType/TypeExists to probe without erroring.

Parameters
nameThe type name to look up.

◆ GetTypeKind

#define GetTypeKind (   ty)    __builtin_ast_type_kind(ty)

Return the TypeKind tag of a type.

Parameters
tyThe type to inspect.

◆ GlobalAt

#define GlobalAt (   i)    __builtin_ast_global_at(i)

Return the global symbol at the given index.

Parameters
iZero-based global index.

◆ GlobalCount

#define GlobalCount ( )    __builtin_ast_global_count()

Return the total number of global symbols.

◆ GlobalVar

#define GlobalVar (   name,
  ty 
)    __builtin_ast_global_var(name, ty)

Create a new named global variable definition.

Parameters
nameThe variable name (must be unique among globals).
tyThe variable type.

◆ GlobalVarSetInitData

#define GlobalVarSetInitData (   var,
  data,
  len 
)     __builtin_ast_global_var_set_init_data(var, data, len)

Set the initial data for a generated global variable.

Parameters
varThe global variable object.
dataPointer to the raw byte data.
lenNumber of bytes to copy (must equal var's type size).

◆ GlobalVarSetStatic

#define GlobalVarSetStatic (   var,
  is_static 
)     __builtin_ast_global_var_set_static(var, is_static)

Set the static (internal linkage) flag on a generated global.

Parameters
varThe global variable object.
is_staticTrue for internal (file-scope static) linkage.

◆ GotoJumpKind

#define GotoJumpKind (   node)    __builtin_ast_goto_jump_kind(node)

Return which statement an NK_GOTO came from (AST_JUMP_*).

Parameters
nodeThe node to inspect.

◆ InitArray

#define InitArray (   elem_ty,
  ... 
)
Value:
elem_ty, (Node *[]){__VA_ARGS__}, \
(int)(sizeof((Node *[]){__VA_ARGS__}) / sizeof(Node *)))
Node * __builtin_ast_init_array(Type *elem_ty, Node **elems, int n)
Build an array compound literal. Element type is explicit to avoid long-inference surprises with Make...

Build an array compound literal with an explicit element type.

Array compound literal with explicit element type.

Parameters
elem_tyThe array element type.
...Node* element values; count is inferred from the argument list.

◆ InitStruct

#define InitStruct (   ty,
  fields,
  values,
  n 
)     __builtin_ast_init_struct(ty, fields, values, n)

Build a designated struct/union initializer; unmentioned fields are zero-initialised.

Designated struct/union init — fields and values are separate arrays.

Parameters
tyThe struct/union type.
fieldsArray of field-name strings.
valuesArray of Node* values, parallel to fields.
nNumber of (field, value) pairs.

Partial init (n less than the member count) is allowed.

◆ LabelName

#define LabelName (   node)    __builtin_ast_label_name(node)

Return the name of an NK_GOTO, NK_LABEL or NK_LABEL_VAL.

Parameters
nodeThe node to inspect.

◆ LoopSetBody

#define LoopSetBody (   loop,
  body 
)    __builtin_ast_loop_set_body(loop, body)

Attach body to loop (from MakeWhile/MakeFor/MakeDoWhile).

Parameters
loopThe loop node to attach the body to.
bodyThe loop body statement.

◆ MacroCallArgAt

#define MacroCallArgAt (   node,
  i 
)    __builtin_ast_macro_call_arg_at(node, i)

Return an argument of an NK_MACRO_CALL.

Parameters
nodeThe node to inspect.
iZero-based argument index.

◆ MacroCallArgCount

#define MacroCallArgCount (   node)    __builtin_ast_macro_call_arg_count(node)

Return the argument count of an NK_MACRO_CALL.

Parameters
nodeThe node to inspect.

◆ MacroCallName

#define MacroCallName (   node)    __builtin_ast_macro_call_name(node)

Return the macro name of a not-yet-expanded NK_MACRO_CALL.

Parameters
nodeThe node to inspect.

◆ MacroErrorAt

#define MacroErrorAt (   node,
  ... 
)    __builtin_macro_error_at(node, __VA_ARGS__)

Emit a compiler error pointing at node's source location.

Parameters
nodeA node whose tok field provides file/line/col, or NULL.
...printf-style format string, followed by format arguments.

◆ MacroExpand

#define MacroExpand (   node)    __builtin_macroexpand(node)

Lisp-style full macro expansion; repeats MacroExpand1 until the form is stable.

Parameters
nodeThe node to fully expand.

◆ MacroExpand1

#define MacroExpand1 (   node)    __builtin_macroexpand_1(node)

Lisp-style single-step macro expansion (macroexpand-1 semantics).

Parameters
nodeThe node to (possibly) expand.

◆ MacroWarningAt

#define MacroWarningAt (   node,
  ... 
)    __builtin_macro_warning_at(node, __VA_ARGS__)

Emit a compiler warning pointing at node's source location (only under -Wcccc-macro).

Parameters
nodeA node whose tok field provides file/line/col, or NULL.
...printf-style format string, followed by format arguments.

◆ MakeAlignofType

#define MakeAlignofType (   ty)    __builtin_ast_alignof_type(ty)

Emit _Alignof(ty) as a compile-time integer literal.

Parameters
tyThe type to measure.

◆ MakeArray

#define MakeArray (   base,
  len 
)    __builtin_ast_make_array(base, len)

Build a fixed-length array type.

Parameters
baseThe element type.
lenThe element count.

◆ MakeAssign

#define MakeAssign (   target,
  value 
)    __builtin_ast_assign(target, value)

Build an assignment node (target = value).

Parameters
targetThe lvalue expression being assigned to.
valueThe rvalue expression to assign.

◆ MakeBinary

#define MakeBinary (   op,
  l,
  r 
)    __builtin_ast_binary(op, l, r)

Build a binary operation AST node.

Parameters
opThe operator kind (NK_ADD, NK_SUB, ...).
lThe left-hand operand.
rThe right-hand operand.

◆ MakeBlock

#define MakeBlock (   stmts,
  count 
)    __builtin_ast_block(stmts, count)

Build a block (compound statement) node.

Parameters
stmtsArray of statement nodes, or NULL if count is 0.
countNumber of statements in the array.

◆ MakeCast

#define MakeCast (   expr,
  ty 
)    __builtin_ast_cast(expr, ty)

Build a type cast AST node.

Parameters
exprThe expression to cast.
tyThe type to cast to.

◆ MakeComma

#define MakeComma (   lhs,
  rhs 
)    __builtin_ast_comma(lhs, rhs)

Build a comma expression: evaluate lhs, yield rhs.

Parameters
lhsThe expression evaluated for side effects.
rhsThe expression whose value is the result.

◆ MakeCond

#define MakeCond (   c,
  t,
  e 
)    __builtin_ast_cond(c, t, e)

Build a ternary conditional expression node (c ? t : e).

Parameters
cThe condition expression.
tThe expression evaluated when c is non-zero.
eThe expression evaluated when c is zero.

◆ MakeConst

#define MakeConst (   ty)    __builtin_ast_make_const(ty)

Return a const-qualified copy of ty.

Parameters
tyThe type to qualify.

◆ MakeDoWhile

#define MakeDoWhile (   body,
  cond 
)    __builtin_ast_do_while(body, cond)

Create a do-while loop node.

Parameters
bodyThe loop body.
condThe loop condition (tested after each iteration).

◆ MakeEnum

#define MakeEnum (   name)    __builtin_ast_make_enum(name)

Create and expose a new named enum type.

Parameters
nameThe enum tag name.

Use EnumAddConstant to add constants after creation.

◆ MakeExprStmt

#define MakeExprStmt (   expr)    __builtin_ast_expr_stmt(expr)

Build an expression statement node.

Parameters
exprThe expression to evaluate for side effects.

◆ MakeFloatLiteral

#define MakeFloatLiteral (   val)    __builtin_ast_float_literal(val)

Build a floating-point literal AST node.

Parameters
valThe floating-point value.

◆ MakeFor

#define MakeFor (   init,
  cond,
  inc,
  body 
)    __builtin_ast_for(init, cond, inc, body)

Create a for loop node.

Parameters
initInitialiser expression/statement (may be NULL).
condLoop condition (may be NULL for infinite loop).
incIncrement expression (may be NULL).
bodyLoop body.

◆ MakeFuncCall

#define MakeFuncCall (   callee,
  args,
  n 
)    __builtin_ast_funcall(callee, args, n)

Create a function call node.

Parameters
calleeAn expression node that evaluates to a function (or function pointer).
argsArray of argument nodes (may be NULL if n == 0).
nNumber of arguments.

◆ MakeFuncPtrType

#define MakeFuncPtrType (   ret,
  params,
  n 
)     __builtin_ast_make_func_ptr_type(ret, params, n)

Build a pointer-to-function type, e.g. "T (*)(T)".

Parameters
retThe function's return type.
paramsArray of parameter types.
nNumber of entries in params (max 16).

◆ MakeFunction

#define MakeFunction (   name,
  ret_type 
)    __builtin_ast_function(name, ret_type)

Create a new function object, automatically added to the globals list.

Parameters
nameThe function name.
ret_typeThe return type.

◆ MakeIf

#define MakeIf (   c,
  t,
  e 
)    __builtin_ast_if(c, t, e)

Build an if statement node.

Parameters
cThe condition expression.
tThe body executed when c is non-zero.
eThe body executed when c is zero, or NULL.

◆ MakeIntLiteral

#define MakeIntLiteral (   val)    __builtin_ast_int_literal(val)

Build an integer literal AST node.

Parameters
valThe integer value.

◆ MakeLocalVar

#define MakeLocalVar (   name,
  ty 
)    __builtin_ast_local_var(name, ty)

Declare a named local variable in the current function scope.

Parameters
nameThe variable name (user-visible).
tyThe variable type.

For temporaries that must not capture user names, prefer MakeLocalVarUnique.

◆ MakeLocalVarUnique

#define MakeLocalVarUnique (   ty)    __builtin_ast_local_var_unique(ty)

Declare a hygienic (gensym'd) local variable in the current function scope.

Parameters
tyThe variable type.

The safe default for macro temporaries; the generated name cannot collide with a user identifier.

◆ MakeMember

#define MakeMember (   obj,
  name 
)    __builtin_ast_member(obj, name)

Create a struct/union member access node (obj.name).

Parameters
objAn expression node whose type must be a struct or union.
nameThe member name as a NUL-terminated string.

Dereference pointers first (e.g. via MakeUnary(NK_DEREF, ...)); this does not do it for you.

◆ MakeNull

#define MakeNull ( )    __builtin_ast_null()

Build a typed null pointer node: (void *)0.

◆ MakeParamRef

#define MakeParamRef (   fn,
  name 
)    __builtin_ast_param_ref(fn, name)

Build a reference to a function parameter by name.

Parameters
fnThe function object whose parameter is being referenced.
nameThe parameter name.

◆ MakePointer

#define MakePointer (   base)    __builtin_ast_make_pointer(base)

Build a pointer-to-base type.

Parameters
baseThe pointed-to type.

◆ MakeReturn

#define MakeReturn (   expr)    __builtin_ast_return(expr)

Build a return statement node.

Parameters
exprThe value to return (may be NULL for a void return).

◆ MakeSizeofExpr

#define MakeSizeofExpr (   expr)    __builtin_ast_sizeof_expr(expr)

Emit sizeof(expr): resolves the expression's type then its size.

Parameters
exprThe expression whose type to measure.

◆ MakeSizeofType

#define MakeSizeofType (   ty)    __builtin_ast_sizeof_type(ty)

Emit sizeof(ty) as a compile-time integer literal.

Parameters
tyThe type to measure.

◆ MakeStringLiteral

#define MakeStringLiteral (   str)    __builtin_ast_string_literal(str)

Build a string literal AST node.

Parameters
strA NUL-terminated string.

◆ MakeStruct

#define MakeStruct (   name)    __builtin_ast_make_struct(name)

Create and expose a new named struct type.

Parameters
nameThe struct tag name.

Use StructAddField to add fields after creation.

◆ MakeSubscript

#define MakeSubscript (   arr,
  idx 
)    __builtin_ast_subscript(arr, idx)

Build an array subscript node: arr[idx], desugared as *(arr+idx).

Parameters
arrThe array (or pointer) expression.
idxThe index expression.

◆ MakeSwitch

#define MakeSwitch (   cond)    __builtin_ast_switch(cond)

Build a switch statement node.

Parameters
condThe expression to switch on.

Use SwitchAddCase / SwitchSetDefault (or WithSwitch) to populate it.

◆ MakeTypedef

#define MakeTypedef (   name,
  underlying 
)     __builtin_ast_make_typedef(name, underlying)

Register a typedef alias for a type and expose it in scope.

Parameters
nameThe typedef name.
underlyingThe aliased type.

◆ MakeUnary

#define MakeUnary (   op,
  operand 
)    __builtin_ast_unary(op, operand)

Build a unary operation AST node.

Parameters
opThe operator kind (NK_NEG, NK_DEREF, ...).
operandThe operand expression.

◆ MakeUnion

#define MakeUnion (   name)    __builtin_ast_make_union(name)

Create and expose a new named union type.

Parameters
nameThe union tag name.

◆ MakeVarRef

#define MakeVarRef (   name)    __builtin_ast_var_ref(name)

Build a variable reference AST node.

Parameters
nameThe variable name.

◆ MakeVolatile

#define MakeVolatile (   ty)    __builtin_ast_make_volatile(ty)

Return a volatile-qualified copy of ty.

Parameters
tyThe type to qualify.

◆ MakeWhile

#define MakeWhile (   cond,
  body 
)    __builtin_ast_while(cond, body)

Create a while loop node.

Parameters
condThe loop condition expression.
bodyThe loop body statement.

◆ MarkAsBuild

#define MarkAsBuild (   fn)    AddAttribute(fn, "cccc::build")

Shorthand for AddAttribute(fn, "cccc::build").

Parameters
fnThe function object.

◆ MarkAsBuildTarget

#define MarkAsBuildTarget (   fn,
  kind 
)     __builtin_ast_add_build_target_attr(fn, kind)

Mark fn as a [[cccc::build_target]] factory of the given kind.

Parameters
fnThe function object.
kindThe build-target kind string.

◆ MarkAsTest

#define MarkAsTest (   fn)    AddAttribute(fn, "cccc::test")

Shorthand for AddAttribute(fn, "cccc::test").

Parameters
fnThe function object.

◆ MemberAttrArg

#define MemberAttrArg (   m,
  name,
  i 
)    __builtin_ast_member_attr_arg(m, name, i)

Return argument i of the first use of name as an expression node.

Parameters
mThe member.
nameAttribute name.
iArgument index.

◆ MemberAttrArgAt

#define MemberAttrArgAt (   m,
  i,
  j 
)    __builtin_ast_member_attr_arg_at(m, i, j)

Return argument j of attribute use i as an expression node.

Parameters
mThe member.
iUse index.
jArgument index.

◆ MemberAttrArgCount

#define MemberAttrArgCount (   m,
  name 
)    __builtin_ast_member_attr_arg_count(m, name)

Return the argument count of the first use of name, or -1 if absent.

Parameters
mThe member.
nameAttribute name.

◆ MemberAttrArgCountAt

#define MemberAttrArgCountAt (   m,
  i 
)    __builtin_ast_member_attr_arg_count_at(m, i)

Return the argument count of attribute use i.

Parameters
mThe member.
iUse index.

◆ MemberAttrCount

#define MemberAttrCount (   m)    __builtin_ast_member_attr_count(m)

Return the number of custom attribute uses on the member.

Parameters
mThe member.

◆ MemberAttrNameAt

#define MemberAttrNameAt (   m,
  i 
)    __builtin_ast_member_attr_name_at(m, i)

Return the name of attribute use i.

Parameters
mThe member.
iUse index.

◆ MemberBitfieldWidth

#define MemberBitfieldWidth (   m)    __builtin_ast_member_bitfield_width(m)

Return the bit width of a bitfield member.

Parameters
mThe member to inspect.

◆ MemberHasAttr

#define MemberHasAttr (   m,
  name 
)    __builtin_ast_member_has_attr(m, name)

Return 1 if the member carries the custom attribute name.

Parameters
mThe member.
nameAttribute name without the @.

◆ MemberIsBitfield

#define MemberIsBitfield (   m)    __builtin_ast_member_is_bitfield(m)

Test whether a member is a bitfield.

Parameters
mThe member to inspect.

◆ MemberName

#define MemberName (   m)    __builtin_ast_member_name(m)

Return the name of a struct/union member.

Parameters
mThe member to inspect.

◆ MemberOffset

#define MemberOffset (   m)    __builtin_ast_member_offset(m)

Return the byte offset of a struct/union member.

Parameters
mThe member to inspect.

◆ MemberType

#define MemberType (   m)    __builtin_ast_member_type(m)

Return the type of a struct/union member.

Parameters
mThe member to inspect.

◆ Memcpy

#define Memcpy (   dst,
  src,
  n 
)
Value:
(Node *[]){(dst), (src), (n)}, 3)
Node * __builtin_ast_funcall(Node *callee, Node **args, int n)
Create a function call node.
Node * __builtin_ast_var_ref(const char *name)
Build a variable reference AST node.

Build a call node to memcpy(dst, src, n).

Parameters
dstDestination expression.
srcSource expression.
nByte count expression.

◆ NodeBody

#define NodeBody (   node)    __builtin_ast_node_body(node)

Return the statement list of an NK_BLOCK or NK_STMT_EXPR.

Parameters
nodeThe node to inspect.

◆ NodeCond

#define NodeCond (   node)    __builtin_ast_node_cond(node)

Return the condition of an if, loop, switch or ?: node.

Parameters
nodeThe node to inspect.

◆ NodeElse

#define NodeElse (   node)    __builtin_ast_node_else(node)

Return the else-branch of an if or ?: node.

Parameters
nodeThe node to inspect.

◆ NodeFloatValue

#define NodeFloatValue (   node)    __builtin_ast_node_float_value(node)

Return the value of a floating NK_NUM literal.

Parameters
nodeThe node to inspect.

◆ NodeInc

#define NodeInc (   node)    __builtin_ast_node_inc(node)

Return the increment of a for node.

Parameters
nodeThe node to inspect.

◆ NodeInit

#define NodeInit (   node)    __builtin_ast_node_init(node)

Return the initialiser of a for node.

Parameters
nodeThe node to inspect.

◆ NodeIntValue

#define NodeIntValue (   node)    __builtin_ast_node_int_value(node)

Return the value of an integer NK_NUM literal.

Parameters
nodeThe node to inspect.

◆ NodeLhs

#define NodeLhs (   node)    __builtin_ast_node_lhs(node)

Return the left operand (or sole operand) of a node.

Parameters
nodeThe node to inspect.

◆ NodeList

#define NodeList (   nodes,
  count 
)    __builtin_node_list(nodes, count)

Build a ->next-linked node chain from an array, for use as a $@k list-splice argument.

Parameters
nodesArray of Node* to link together.
countNumber of elements in the array.

◆ NodeMember

#define NodeMember (   node)    __builtin_ast_node_member(node)

Return the member an NK_MEMBER node selects.

Parameters
nodeThe node to inspect.

◆ NodeNext

#define NodeNext (   node)    __builtin_ast_node_next(node)

Return the next node in a statement or argument list.

Parameters
nodeThe node to inspect.

◆ NodeRhs

#define NodeRhs (   node)    __builtin_ast_node_rhs(node)

Return the right operand of a node.

Parameters
nodeThe node to inspect.

◆ NodeThen

#define NodeThen (   node)    __builtin_ast_node_then(node)

Return the then-branch of an if or ?: node, or the body of a loop or switch.

Parameters
nodeThe node to inspect.

◆ NodeVarObj

#define NodeVarObj (   node)    __builtin_ast_node_var_obj(node)

Return the variable an NK_VAR (or NK_MEMZERO) node refers to.

Parameters
nodeThe node to inspect.

◆ ObjIsDefinition

#define ObjIsDefinition (   obj)    __builtin_ast_obj_is_definition(obj)

Test whether a global object has a definition.

Parameters
objThe object to inspect.

◆ ObjIsFunction

#define ObjIsFunction (   obj)    __builtin_ast_obj_is_function(obj)

Test whether a global object is a function.

Parameters
objThe object to inspect.

◆ ObjIsStatic

#define ObjIsStatic (   obj)    __builtin_ast_obj_is_static(obj)

Test whether a global object has internal (static) linkage.

Parameters
objThe object to inspect.

◆ ObjName

#define ObjName (   obj)    __builtin_ast_obj_name(obj)

Return the name of a global object.

Parameters
objThe object to inspect.

◆ ObjNext

#define ObjNext (   obj)    __builtin_ast_obj_next(obj)

Return the next Obj in the list that holds obj.

Parameters
objA parameter, local or global Obj.

◆ ObjType

#define ObjType (   obj)    __builtin_ast_obj_type(obj)

Return the type of a global object.

Parameters
objThe object to inspect.

◆ OffsetofChain

#define OffsetofChain (   type,
  ... 
)
Value:
type, (const char *[]){__VA_ARGS__}, \
(int)(sizeof((const char *[]){__VA_ARGS__}) / sizeof(const char *))))
int64_t __builtin_ast_offsetof_chain(Type *ty, const char **names, int n)
Compute the byte offset of a (possibly nested) member chain.

Compute the byte offset of a (possibly nested) member chain as a MakeIntLiteral AST node.

Parameters
typeThe starting struct/union type.
...Member names to walk, innermost last.

◆ OverflowOp

#define OverflowOp (   node)    __builtin_ast_overflow_op(node)

Return the operation (AST_OVERFLOW_*) of an NK_OVERFLOW_ARITH.

Parameters
nodeAn NK_OVERFLOW_ARITH node.

◆ OverflowResultPtr

#define OverflowResultPtr (   node)    __builtin_ast_overflow_result_ptr(node)

Return the result pointer of an NK_OVERFLOW_ARITH.

Parameters
nodeAn NK_OVERFLOW_ARITH node.

◆ ParamAttrArg

#define ParamAttrArg (   p,
  name,
  i 
)    __builtin_ast_param_attr_arg(p, name, i)

Return argument i of the first use of name as an expression node.

Parameters
pThe parameter type.
nameAttribute name.
iArgument index.

◆ ParamAttrArgAt

#define ParamAttrArgAt (   p,
  i,
  j 
)    __builtin_ast_param_attr_arg_at(p, i, j)

Return argument j of attribute use i as an expression node.

Parameters
pThe parameter type.
iUse index.
jArgument index.

◆ ParamAttrArgCount

#define ParamAttrArgCount (   p,
  name 
)    __builtin_ast_param_attr_arg_count(p, name)

Return the argument count of the first use of name, or -1 if absent.

Parameters
pThe parameter type.
nameAttribute name.

◆ ParamAttrArgCountAt

#define ParamAttrArgCountAt (   p,
  i 
)    __builtin_ast_param_attr_arg_count_at(p, i)

Return the argument count of attribute use i.

Parameters
pThe parameter type.
iUse index.

◆ ParamAttrCount

#define ParamAttrCount (   p)    __builtin_ast_param_attr_count(p)

Return the number of custom attribute uses on the parameter.

Parameters
pThe parameter type.

◆ ParamAttrNameAt

#define ParamAttrNameAt (   p,
  i 
)    __builtin_ast_param_attr_name_at(p, i)

Return the name of attribute use i.

Parameters
pThe parameter type.
iUse index.

◆ ParamHasAttr

#define ParamHasAttr (   p,
  name 
)    __builtin_ast_param_has_attr(p, name)

Return 1 if the parameter carries the custom attribute name.

Parameters
pThe parameter type (from TypeParamAt).
nameAttribute name without the @.

◆ PublishNode

#define PublishNode (   decl)
Value:
_Generic((decl), \
Type *: __builtin_ast_publish_type)((decl), 0)
Node * __builtin_ast_publish_type(Type *ty, Token *tok)
Accept a generated type declaration as already published.
Node * __builtin_ast_publish(Obj *obj, Token *tok)
Make a generated object visible at the current source position.

Make a generated declaration visible at the current source position.

Parameters
declAn Obj* (function/global) or Type* created by the AST builders.

Dispatches on the argument's type via _Generic: Obj* goes to __builtin_ast_publish, Type* to __builtin_ast_publish_type.

◆ PublishNodeAt

#define PublishNodeAt (   decl,
  tok 
)
Value:
_Generic((decl), \
Type *: __builtin_ast_publish_type)((decl), (tok))

Like PublishNode, but attaches an explicit diagnostic token.

Parameters
declAn Obj* (function/global) or Type* created by the AST builders.
tokRepresentative token for diagnostics, or NULL.

◆ Quote

#define Quote (   tmpl,
  ... 
)    __builtin_quote(tmpl, ##__VA_ARGS__)

Parse a C code template string into an AST node, substituting $N / $@N splice points with the given argument nodes.

Parameters
tmplA C expression or statement as a string literal with splice points.
...Node* arguments corresponding to the splice points (up to 64; use QuoteN for more).
Note
A template with more than one top-level statement does not need explicit braces: Quote("a; b; return c;") and Quote("{ a; b; return c; }") parse to the same block, and every statement is kept either way. A ';' inside a nested (...)/[...]/{...} (e.g. a for(a;b;c) header) is not treated as a top-level separator. Any tokens left unparsed once the template's statement(s) or expression have been consumed are a compile error rather than being silently discarded.

◆ QuoteLazy

#define QuoteLazy (   tmpl,
  ... 
)    __builtin_quote_lazy(tmpl, ##__VA_ARGS__)

Capture a C code template and its splice arguments without parsing it; the template is parsed only once spliced into another Quote()/QuoteLazy() template or passed to FunctionSetBody, at that splice site's own scope and loop context.

Parameters
tmplA C expression or statement as a string literal with splice points, exactly as for Quote().
...Node* arguments corresponding to the splice points (up to 64; use QuoteLazyN for more).
Note
Use this instead of Quote() when the fragment references a variable, or uses break/continue targeting a loop, that only exists once the fragment lands at its splice site – see Quote for ordinary (eager) quasi-quoting. Not valid as a $@N list-splice argument.

◆ QuoteLazyN

#define QuoteLazyN (   tmpl,
  nodes,
  count 
)     __builtin_quote_lazy_n(tmpl, nodes, count)

Array-form QuoteLazy; validates the splice count at the capture site and supports more nodes than QuoteLazy's variadic form.

Parameters
tmplTemplate string with $N / $@N splice points.
nodesArray of Node* splice arguments.
countLength of the nodes array.
Note
See QuoteLazy.

◆ QuoteN

#define QuoteN (   tmpl,
  nodes,
  count 
)    __builtin_quote_n(tmpl, nodes, count)

Array-form quasi-quote that validates the splice count and supports more nodes than Quote's variadic form.

Parameters
tmplTemplate string with $N / $@N splice points.
nodesArray of Node* splice arguments.
countLength of the nodes array.
Note
See Quote for the multi-statement and trailing-token parsing rules.

◆ Serialize

#define Serialize (   ty,
  expr,
  buf 
)    __builtin_ast_serialize(ty, expr, buf)

Build a block of memcpy() calls copying expr (of type ty) into buf.

Parameters
tyThe type of expr.
exprThe expression to serialize.
bufA void or char pointer destination.

Struct/union types are copied member-by-member at their natural offsets; padding is not written and buf needs no particular alignment. Pointer members are copied as raw bytes, not followed.

◆ SetToken

#define SetToken (   node,
  tok 
)    __builtin_ast_set_token(node, tok)

Attach an opaque source token to node.

Parameters
nodeNode to update.
tokToken from CurrentToken(), SyntheticToken(), or TokenFromNode().

◆ Strcmp

#define Strcmp (   a,
  b 
)
Value:
(Node *[]){(a), (b)}, 2)

Build a call node to strcmp(a, b).

Parameters
aFirst string expression.
bSecond string expression.

◆ StringLiteralValue

#define StringLiteralValue (   node)    __builtin_ast_string_literal_value(node)

Return the text of a string literal node, or NULL.

Parameters
nodeA node, typically a macro or attribute argument.

◆ StripImplicit

#define StripImplicit (   node)    __builtin_ast_node_strip_implicit(node)

Peel compiler-inserted casts and call wrappers off a node.

Parameters
nodeThe node to inspect.

◆ Strlen

#define Strlen (   s)     __builtin_ast_funcall(__builtin_ast_var_ref("strlen"), (Node *[]){(s)}, 1)

Build a call node to strlen(s).

Parameters
sString expression.

◆ StructAddField

#define StructAddField (   ...)
Value:
#define __builtin_struct_add_field_3(ty, name, field_type)
Definition reflection.h:3267
#define __builtin_struct_add_field_2(name, field_type, _ignored)
Definition reflection.h:3265

Append a field to a struct or union and recompute its layout.

Parameters
...Either (name, field_type) inside a WithStruct(ty) block, or (ty, name, field_type) to name the type explicitly.

Works for both struct and union types; dispatches on argument count via __builtin_dispatch_3.

◆ StructMemberAt

#define StructMemberAt (   ty,
  i 
)    __builtin_ast_struct_member_at(ty, i)

Return the member at the given index.

Parameters
tyThe struct or union type to inspect.
iZero-based member index.

◆ StructMemberCount

#define StructMemberCount (   ty)    __builtin_ast_struct_member_count(ty)

Return the number of members of a struct or union type.

Parameters
tyThe struct or union type to inspect.

◆ StructMemberFind

#define StructMemberFind (   ty,
  name 
)    __builtin_ast_struct_member_find(ty, name)

Look up a struct or union member by name.

Parameters
tyThe struct or union type to search.
nameThe member name to look up.

◆ SwitchAddCase

#define SwitchAddCase (   ...)
Value:
#define __builtin_switch_add_case_2(v, b, _ignored)
Definition reflection.h:2479
#define __builtin_switch_add_case_3(sw, v, b)
Definition reflection.h:2481

Append a case to a switch statement.

Parameters
...Either (value, body) inside a WithSwitch(sw) block, or (sw, value, body) to name the switch explicitly.

Dispatches on argument count via __builtin_dispatch_3.

◆ SwitchCaseAt

#define SwitchCaseAt (   sw,
  i 
)    __builtin_ast_switch_case_at(sw, i)

Return a case label of a switch, in source order.

Parameters
swAn NK_SWITCH node.
iZero-based case index.

◆ SwitchCaseCount

#define SwitchCaseCount (   sw)    __builtin_ast_switch_case_count(sw)

Return the number of case labels of a switch (excluding default).

Parameters
swAn NK_SWITCH node.

◆ SwitchDefault

#define SwitchDefault (   sw)    __builtin_ast_switch_default(sw)

Return the default label of a switch.

Parameters
swAn NK_SWITCH node.

◆ SwitchSetDefault

#define SwitchSetDefault (   ...)
Value:
#define __builtin_switch_set_default_1(b, _ignored)
Definition reflection.h:2491
#define __builtin_switch_set_default_2(sw, b)
Definition reflection.h:2493

Set the default case for a switch statement.

Parameters
...Either (body) inside a WithSwitch(sw) block, or (sw, body) to name the switch explicitly.

Dispatches on argument count via __builtin_dispatch_2.

◆ SyntheticToken

#define SyntheticToken (   label)    __builtin_ast_synthetic_token(label)

Create an opaque synthetic source token for generated AST nodes.

Parameters
labelShort diagnostic label for the synthetic location.

◆ TokenFromNode

#define TokenFromNode (   node)    __builtin_ast_token_from_node(node)

Return the opaque source token attached to node.

Parameters
nodeNode to inspect.

◆ TypeAlign

#define TypeAlign (   ty)    __builtin_ast_type_align(ty)

Return _Alignof(ty) in bytes.

Parameters
tyThe type to inspect.

◆ TypeArrayLen

#define TypeArrayLen (   ty)    __builtin_ast_type_array_len(ty)

Return the fixed length of an array type.

Parameters
tyThe array type to inspect.

◆ TypeBase

#define TypeBase (   ty)    __builtin_ast_type_base(ty)

Return the element type of a pointer or array.

Parameters
tyThe pointer/array type to inspect.

◆ TypeCName

#define TypeCName (   ty)    __builtin_ast_type_c_name(ty)

Return a valid C identifier fragment naming ty (for naming generated functions).

Parameters
tyThe type to inspect.

◆ TypeExists

#define TypeExists (   name)    __builtin_ast_type_exists(name)

Check whether a type is currently in scope by name.

Parameters
nameThe type name to look up.

◆ TypeIsConst

#define TypeIsConst (   ty)    __builtin_ast_type_is_const(ty)

Test whether a type is const-qualified.

Parameters
tyThe type to inspect.

◆ TypeIsUnsigned

#define TypeIsUnsigned (   ty)    __builtin_ast_type_is_unsigned(ty)

Test whether an integer type is unsigned.

Parameters
tyThe type to inspect.

◆ TypeIsVariadic

#define TypeIsVariadic (   ty)    __builtin_ast_type_is_variadic(ty)

Test whether a function type is variadic.

Parameters
tyThe type to inspect.

◆ TypeName

#define TypeName (   ty)    __builtin_ast_type_name(ty)

Return the user-visible name of a type, if any.

Parameters
tyThe type to inspect.

◆ TypeParamAt

#define TypeParamAt (   ty,
  i 
)    __builtin_ast_type_param_at(ty, i)

Return the type of the parameter at the given index.

Parameters
tyThe function type to inspect.
iZero-based parameter index.

◆ TypeParamCount

#define TypeParamCount (   ty)    __builtin_ast_type_param_count(ty)

Return the number of declared parameters of a function type.

Parameters
tyThe function type to inspect.

◆ TypeReturnType

#define TypeReturnType (   ty)    __builtin_ast_type_return_type(ty)

Return the return type of a function type.

Parameters
tyThe function type to inspect.

◆ TypeSize

#define TypeSize (   ty)    __builtin_ast_type_size(ty)

Return sizeof(ty) in bytes.

Parameters
tyThe type to inspect.

◆ VarargAsArray

#define VarargAsArray ( )    __builtin_ast_varargs_as_array()

Return an inline macro's variadic AST arguments as a borrowed array.

◆ VarargAt

#define VarargAt (   i)    __builtin_ast_vararg_at(i)

Return an inline macro's variadic AST argument by zero-based index.

Parameters
iZero-based variadic argument index.

◆ VarargCount

#define VarargCount ( )    __builtin_ast_vararg_count()

Return the number of variadic arguments for the active macro call.

◆ VarargStrAt

#define VarargStrAt (   i)    __builtin_ast_vararg_str_at(i)

Return a global-generation macro's stringified variadic argument by index.

Parameters
iZero-based variadic argument index.

◆ WithBlock

#define WithBlock (   block)
Value:
for (int _cccc_block_ctx_ = (__builtin_ast_push_block((block)), 1); \
_cccc_block_ctx_; _cccc_block_ctx_ = (__builtin_ast_pop_block(), 0))
void __builtin_ast_pop_block(void)
void __builtin_ast_push_block(Node *block)
Establish a block as the current statement-append context.

Block helper: establishes block as the current statement-append context so BlockAddStmt(stmt) appends to it.

Parameters
blockThe NK_BLOCK node being populated.

Implemented as a single-iteration for loop; use continue rather than break to exit early so the pop still runs.

◆ WithEnum

#define WithEnum (   ty)
Value:
for (int _cccc_enum_ctx_ = (__builtin_ast_push_enum((ty)), 1); \
_cccc_enum_ctx_; _cccc_enum_ctx_ = (__builtin_ast_pop_enum(), 0))
void __builtin_ast_push_enum(Type *ty)
Establish an enum as the current constant-add context.
void __builtin_ast_pop_enum(void)

Block helper: establishes ty as the current constant-add context so EnumAddConstant(name, value) appends to it.

Parameters
tyThe enum type being populated.

Implemented as a single-iteration for loop; use continue rather than break to exit early so the pop still runs.

◆ WithFn

#define WithFn (   fn)
Value:
for (int _cccc_fn_ctx_ = (__builtin_ast_push_fn((fn)), 1); _cccc_fn_ctx_; \
_cccc_fn_ctx_ = (__builtin_ast_pop_fn(), 0))
void __builtin_ast_push_fn(Obj *fn)
Establish fn as the "function currently being built" so that Quote("return x;") applies the correct i...
void __builtin_ast_pop_fn(void)
Restore the function context saved by the most recent push.

Block helper: establishes fn as the current function-building context so Quote("return x;") applies the correct return-type cast.

Parameters
fnThe generated function whose return type should be used.

Implemented as a single-iteration for loop; the pop runs in the loop increment. Exit the block with continue, not break — break skips the increment and leaves the context unrestored.

◆ WithLoop

#define WithLoop (   loop)
Value:
for (int _cccc_loop_ctx_ = (__builtin_ast_push_loop((loop)), 1); \
_cccc_loop_ctx_; _cccc_loop_ctx_ = (__builtin_ast_pop_loop(), 0))
void __builtin_ast_pop_loop(void)
Restore the loop context saved by the most recent push.
void __builtin_ast_push_loop(Node *loop)
Establish loop as the current loop context, so an eagerly-parsed Quote("break;")/Quote("continue;") c...

Scoped block establishing loop as the current loop context, so an eager Quote("break;")/Quote("continue;") call inside the block resolves against loop's own break/continue targets.

Parameters
loopA loop node returned by MakeWhile/MakeFor/MakeDoWhile.

◆ WithStruct

#define WithStruct (   ty)
Value:
for (int _cccc_struct_ctx_ = (__builtin_ast_push_struct((ty)), 1); \
_cccc_struct_ctx_; \
_cccc_struct_ctx_ = (__builtin_ast_pop_struct(), 0))
void __builtin_ast_push_struct(Type *ty)
Establish a struct or union as the current field-add context.
void __builtin_ast_pop_struct(void)

Block helper: establishes ty as the current field-add context so StructAddField(name, ty) appends to it.

Parameters
tyThe aggregate type being populated.

Implemented as a single-iteration for loop; use continue rather than break to exit early so the pop still runs.

◆ WithSwitch

#define WithSwitch (   sw)
Value:
for (int _cccc_switch_ctx_ = (__builtin_ast_push_switch((sw)), 1); \
_cccc_switch_ctx_; \
_cccc_switch_ctx_ = (__builtin_ast_pop_switch(), 0))
void __builtin_ast_pop_switch(void)
void __builtin_ast_push_switch(Node *switch_node)
Establish a switch node as the current case/default context.

Block helper: establishes sw as the current case/default context so SwitchAddCase / SwitchSetDefault populate it.

Parameters
swThe switch node being populated.

Implemented as a single-iteration for loop; use continue rather than break to exit early so the pop still runs.

Enumeration Type Documentation

◆ AstBitop

enum AstBitop

The operation of an NK_BITOP node, returned by BitopOp(node).

Enumerator
AST_BITOP_CLZ 
AST_BITOP_CTZ 
AST_BITOP_POPCOUNT 
AST_BITOP_PARITY 
AST_BITOP_FFS 
AST_BITOP_BSWAP 

◆ AstJumpKind

Which statement an NK_GOTO node came from, returned by GotoJumpKind(node).

Enumerator
AST_JUMP_GOTO 
AST_JUMP_BREAK 
AST_JUMP_CONTINUE 

◆ AstOverflowOp

The operation of an NK_OVERFLOW_ARITH node, returned by OverflowOp(node).

Enumerator
AST_OVERFLOW_ADD 
AST_OVERFLOW_SUB 
AST_OVERFLOW_MUL 

◆ AttrTargetKind

Discriminates the kind of declaration an AttrTarget refers to, returned by GetAttrTargetKind(target) inside a custom @attribute handler.

Enumerator
ATTR_TARGET_TYPEDEF 
ATTR_TARGET_TYPE 
ATTR_TARGET_FUNCTION 
ATTR_TARGET_GLOBAL 
ATTR_TARGET_MEMBER 
ATTR_TARGET_PARAM 

◆ NodeKind

enum NodeKind

Discriminates the operator/statement kind of a Node, e.g. as passed to MakeBinary / MakeUnary, returned by GetNodeKind, or matched against a node's ->kind field.

Mirrors cccc.h's internal ND_* node kinds one for one; the numeric values are identical.

Enumerator
NK_NULL_EXPR 
NK_ADD 
NK_SUB 
NK_MUL 
NK_DIV 
NK_NEG 
NK_MOD 
NK_BITAND 
NK_BITOR 
NK_BITXOR 
NK_SHL 
NK_SHR 
NK_EQ 
NK_NE 
NK_LT 
NK_LE 
NK_ASSIGN 
NK_COND 
NK_COMMA 
NK_MEMBER 
NK_ADDR 
NK_DEREF 
NK_NOT 
NK_BITNOT 
NK_LOGAND 
NK_LOGOR 
NK_RETURN 
NK_IF 
NK_FOR 
NK_DO 
NK_SWITCH 
NK_CASE 
NK_BLOCK 
NK_GOTO 
NK_GOTO_EXPR 
NK_LABEL 
NK_LABEL_VAL 
NK_FUNCALL 
NK_EXPR_STMT 
NK_STMT_EXPR 
NK_VAR 
NK_VLA_PTR 
NK_NUM 
NK_CAST 
NK_MEMZERO 
NK_ASM 
NK_CAS 
NK_EXCH 
NK_FRAME_ADDR 
NK_BLOCK_LITERAL 
NK_BLOCK_CALL 
NK_MACRO_CALL 
NK_COMPLEX 
NK_UNREACHABLE 
NK_BITOP 
NK_OVERFLOW_ARITH 
NK_INIT_SPLICE 
NK_ALOAD 
NK_ASTORE 
NK_RETURN_ADDR 
NK_DYNOBJ_SIZE 
NK_CONVERTVECTOR 
NK_DECIMAL_TO_CHARS 
NK_FENCE 
NK_QUOTE_LAZY 
NK_DYNAMIC_CHECK 
NK_VA_NAMED_COUNT 

◆ TypeKind

enum TypeKind

Discriminates the kind of a Type: primitive, pointer, array, function, struct/union, or enum.

Mirrors the subset of cccc.h's internal TypeKind relevant to comptime functions. Query it via GetTypeKind(ty).

Enumerator
TK_VOID 
TK_BOOL 
TK_CHAR 
TK_SHORT 
TK_INT 
TK_LONG 
TK_FLOAT 
TK_DOUBLE 
TK_LDOUBLE 
TK_ENUM 
TK_PTR 
TK_FUNC 
TK_ARRAY 
TK_VLA 
TK_STRUCT 
TK_UNION 

Function Documentation

◆ __builtin_ast_add_attribute()

void __builtin_ast_add_attribute ( Obj *  fn,
const char *  attr_text 
)

Apply an attribute string to a programmatically created function.

Parameters
fnThe function object to attribute (created by MakeFunction).
attr_textAttribute text as it would appear between [[ and ]] in source, e.g. "cccc::test", "cccc::test(suite=\"gen\", timeout=5000)", "nodiscard", "nodiscard(\"always check\")", or "@myattr". GNU form attribute((…)) is also accepted as the full string.

Parses attr_text through the existing attribute pipeline and applies the result to fn. Supports mode attrs (test/build/build_target/ test_setup/test_teardown), standard C23/GNU attrs (nodiscard, noreturn, pure, aligned, …), and custom @attribute handlers. cccc::comptime cannot be applied this way and will error. Convenience wrapper: AddAttribute(fn, text).

◆ __builtin_ast_add_build_target_attr()

void __builtin_ast_add_build_target_attr ( Obj *  fn,
const char *  kind 
)

◆ __builtin_ast_alignof_type()

Node * __builtin_ast_alignof_type ( Type *  ty)

Emit _Alignof(ty) as a compile-time integer literal.

Parameters
tyThe type to measure.
Returns
An NK_NUM node holding _Alignof(ty).

Convenience wrapper: MakeAlignofType(ty).

◆ __builtin_ast_asm_clobber_at()

const char * __builtin_ast_asm_clobber_at ( Node *  node,
int  index 
)

Return a clobber of an NK_ASM statement.

Parameters
nodeAn NK_ASM node.
indexZero-based clobber index.
Returns
The clobber string, or NULL when out of range.

Convenience wrapper: AsmClobberAt(node, i).

◆ __builtin_ast_asm_clobber_count()

int __builtin_ast_asm_clobber_count ( Node *  node)

Return the number of clobbers of an NK_ASM statement.

Parameters
nodeAn NK_ASM node.
Returns
The count, 0 for other kinds.

Convenience wrapper: AsmClobberCount(node).

◆ __builtin_ast_asm_goto_label_at()

const char * __builtin_ast_asm_goto_label_at ( Node *  node,
int  index 
)

Return a jump label name of an asm goto.

Parameters
nodeAn NK_ASM node.
indexZero-based label index.
Returns
The label name, or NULL when out of range.

Convenience wrapper: AsmGotoLabelAt(node, i).

◆ __builtin_ast_asm_goto_label_count()

int __builtin_ast_asm_goto_label_count ( Node *  node)

Return the number of jump labels of an asm goto.

Parameters
nodeAn NK_ASM node.
Returns
The count, 0 for other kinds.

Convenience wrapper: AsmGotoLabelCount(node).

◆ __builtin_ast_asm_input_count()

int __builtin_ast_asm_input_count ( Node *  node)

Return the number of input operands of an NK_ASM statement.

Parameters
nodeAn NK_ASM node.
Returns
The count, 0 for other kinds.

Convenience wrapper: AsmInputCount(node).

◆ __builtin_ast_asm_is_goto()

bool __builtin_ast_asm_is_goto ( Node *  node)

Return whether an NK_ASM statement is an asm goto.

Parameters
nodeAn NK_ASM node.
Returns
True for asm goto, false otherwise.

Convenience wrapper: AsmIsGoto(node).

◆ __builtin_ast_asm_is_volatile()

bool __builtin_ast_asm_is_volatile ( Node *  node)

Return whether an NK_ASM statement is written volatile.

Parameters
nodeAn NK_ASM node.
Returns
True for volatile asm, false otherwise.

Convenience wrapper: AsmIsVolatile(node).

◆ __builtin_ast_asm_operand_constraint()

const char * __builtin_ast_asm_operand_constraint ( Node *  node,
int  index 
)

Return the constraint string of an asm operand.

Parameters
nodeAn NK_ASM node.
indexZero-based operand index; outputs come before inputs.
Returns
The constraint (e.g. "=r"), or NULL when out of range.

Convenience wrapper: AsmOperandConstraint(node, i).

◆ __builtin_ast_asm_operand_expr()

Node * __builtin_ast_asm_operand_expr ( Node *  node,
int  index 
)

Return the expression of an asm operand.

Parameters
nodeAn NK_ASM node.
indexZero-based operand index; outputs come before inputs.
Returns
The operand expression, or NULL when out of range.

Convenience wrapper: AsmOperandExpr(node, i).

◆ __builtin_ast_asm_operand_name()

const char * __builtin_ast_asm_operand_name ( Node *  node,
int  index 
)

Return the symbolic name of an asm operand.

Parameters
nodeAn NK_ASM node.
indexZero-based operand index; outputs come before inputs.
Returns
The name written as [name], or NULL when unnamed or out of range.

Convenience wrapper: AsmOperandName(node, i).

◆ __builtin_ast_asm_output_count()

int __builtin_ast_asm_output_count ( Node *  node)

Return the number of output operands of an NK_ASM statement.

Parameters
nodeAn NK_ASM node.
Returns
The count, 0 for other kinds.

Convenience wrapper: AsmOutputCount(node).

◆ __builtin_ast_asm_template()

const char * __builtin_ast_asm_template ( Node *  node)

Return the template string of an NK_ASM statement.

Parameters
nodeAn NK_ASM node.
Returns
The template, or NULL for other kinds.

Convenience wrapper: AsmTemplate(node).

◆ __builtin_ast_assign()

Node * __builtin_ast_assign ( Node *  target,
Node *  value 
)

Build an assignment node (target = value).

Parameters
targetThe lvalue expression being assigned to.
valueThe rvalue expression to assign.
Returns
An NK_ASSIGN node, or NULL on error.

Convenience wrapper: MakeAssign(target, value).

◆ __builtin_ast_atomic_fail_order()

int __builtin_ast_atomic_fail_order ( Node *  node)

Return the failure memory order of an NK_CAS.

Parameters
nodeAn NK_CAS node.
Returns
The __ATOMIC_* value, as AtomicOrder; -1 for other kinds.

Convenience wrapper: AtomicFailOrder(node).

◆ __builtin_ast_atomic_is_weak()

bool __builtin_ast_atomic_is_weak ( Node *  node)

Return whether an NK_CAS was written as a weak compare-exchange.

Parameters
nodeAn NK_CAS node.
Returns
True for weak, false otherwise.

Convenience wrapper: AtomicIsWeak(node).

◆ __builtin_ast_atomic_order()

int __builtin_ast_atomic_order ( Node *  node)

Return the memory order of an NK_CAS, NK_EXCH, NK_ALOAD or NK_ASTORE.

Parameters
nodeThe node to inspect.
Returns
The __ATOMIC_* value (0 relaxed to 5 seq_cst); seq_cst when the order is not a constant. -1 for other kinds, since 0 is a valid order.

Convenience wrapper: AtomicOrder(node).

◆ __builtin_ast_binary()

Node * __builtin_ast_binary ( NodeKind  op,
Node *  left,
Node *  right 
)

Build a binary operation AST node.

Parameters
opThe operator kind (NK_ADD, NK_SUB, ...).
leftThe left-hand operand.
rightThe right-hand operand.
Returns
The binary expression node.

Convenience wrapper: MakeBinary(op, left, right).

◆ __builtin_ast_bitop_op()

int __builtin_ast_bitop_op ( Node *  node)

Return the operation of an NK_BITOP.

Parameters
nodeAn NK_BITOP node.
Returns
An AST_BITOP_* value, 0 for other kinds.

Convenience wrapper: BitopOp(node).

◆ __builtin_ast_bitop_width()

int __builtin_ast_bitop_width ( Node *  node)

Return the bit width of an NK_BITOP's builtin.

Parameters
nodeAn NK_BITOP node.
Returns
32 or 64 for clz, ctz and ffs; the swapped width in bits for bswap; 0 for popcount, parity and other kinds.

Convenience wrapper: BitopWidth(node).

◆ __builtin_ast_block()

Node * __builtin_ast_block ( Node **  stmts,
int  count 
)

Build a block (compound statement) node.

Parameters
stmtsArray of statement nodes, or NULL if count is 0.
countNumber of statements in the array.
Returns
An NK_BLOCK node.

Convenience wrapper: MakeBlock(stmts, count).

◆ __builtin_ast_block_add_current_stmt()

Node * __builtin_ast_block_add_current_stmt ( Node *  stmt)

◆ __builtin_ast_block_add_stmt()

Node * __builtin_ast_block_add_stmt ( Node *  block,
Node *  stmt 
)

Append a statement to a block node.

Parameters
blockThe NK_BLOCK node to modify.
stmtThe statement to append.
Returns
The block on success, or NULL on invalid arguments.

Convenience wrapper: BlockAddStmt(block, stmt), or BlockAddStmt(stmt) inside WithBlock(block).

◆ __builtin_ast_block_at()

Node * __builtin_ast_block_at ( Node *  block,
int  index 
)

Return a statement of an NK_BLOCK or NK_STMT_EXPR.

Parameters
blockThe block node.
indexZero-based statement index.
Returns
The statement, or NULL when out of range.

Convenience wrapper: BlockAt(block, i).

◆ __builtin_ast_block_count()

int __builtin_ast_block_count ( Node *  block)

Return the number of statements in an NK_BLOCK or NK_STMT_EXPR.

Parameters
blockThe block node.
Returns
The statement count, 0 for other kinds.

Convenience wrapper: BlockCount(block).

◆ __builtin_ast_call_arg_at()

Node * __builtin_ast_call_arg_at ( Node *  call,
int  index 
)

Return an argument of a call.

Parameters
callAn NK_FUNCALL node (or the comma wrapper around one).
indexZero-based argument index.
Returns
The argument, or NULL when out of range.

Convenience wrapper: CallArgAt(call, i).

◆ __builtin_ast_call_arg_count()

int __builtin_ast_call_arg_count ( Node *  call)

Return the number of arguments of a call.

Parameters
callAn NK_FUNCALL node (or the comma wrapper around one).
Returns
The argument count, 0 for other kinds.

Convenience wrapper: CallArgCount(call).

◆ __builtin_ast_call_callee()

Node * __builtin_ast_call_callee ( Node *  call)

Return the callee expression of a call.

Parameters
callAn NK_FUNCALL node (or the comma wrapper around one).
Returns
The callee, or NULL for other kinds.

Convenience wrapper: CallCallee(call).

◆ __builtin_ast_cas_addr()

Node * __builtin_ast_cas_addr ( Node *  node)

Return the address operand of an NK_CAS.

Parameters
nodeAn NK_CAS node.
Returns
The address expression, or NULL for other kinds.

Convenience wrapper: CasAddr(node).

◆ __builtin_ast_cas_desired()

Node * __builtin_ast_cas_desired ( Node *  node)

Return the desired-value operand of an NK_CAS.

Parameters
nodeAn NK_CAS node.
Returns
The desired-value expression, or NULL for other kinds.

Convenience wrapper: CasDesired(node).

◆ __builtin_ast_cas_expected()

Node * __builtin_ast_cas_expected ( Node *  node)

Return the expected-value operand of an NK_CAS.

Parameters
nodeAn NK_CAS node.
Returns
The expression (the pointer to the expected value), or NULL for other kinds.

Convenience wrapper: CasExpected(node).

◆ __builtin_ast_case_begin()

long long __builtin_ast_case_begin ( Node *  node)

Return the first value of an NK_CASE label.

Parameters
nodeAn NK_CASE node.
Returns
The value, 0 for other kinds.

Convenience wrapper: CaseBegin(node).

◆ __builtin_ast_case_body()

Node * __builtin_ast_case_body ( Node *  node)

Return the statement that follows an NK_CASE label.

Parameters
nodeAn NK_CASE node.
Returns
The statement, or NULL.

Convenience wrapper: CaseBody(node).

◆ __builtin_ast_case_end()

long long __builtin_ast_case_end ( Node *  node)

Return the last value of an NK_CASE label (equal to CaseBegin unless a GNU range).

Parameters
nodeAn NK_CASE node.
Returns
The value, 0 for other kinds.

Convenience wrapper: CaseEnd(node).

◆ __builtin_ast_cast()

Node * __builtin_ast_cast ( Node *  expr,
Type *  target_type 
)

Build a type cast AST node.

Parameters
exprThe expression to cast.
target_typeThe type to cast to.
Returns
An NK_CAST node.

Convenience wrapper: MakeCast(expr, target_type).

◆ __builtin_ast_comma()

Node * __builtin_ast_comma ( Node *  lhs,
Node *  rhs 
)

Build a comma expression: evaluate lhs, yield rhs.

Parameters
lhsThe expression evaluated for side effects.
rhsThe expression whose value is the result.
Returns
An NK_COMMA node.

Convenience wrapper: MakeComma(lhs, rhs).

◆ __builtin_ast_compound_literal()

Node * __builtin_ast_compound_literal ( Type *  ty,
Node **  inits,
int  n 
)

Build a positional compound literal: zero-initialise an anonymous local var then positionally assign inits via node_expand_init_splice.

Note
Requires function scope (file-scope not supported in V1).

◆ __builtin_ast_cond()

Node * __builtin_ast_cond ( Node *  cond,
Node *  then_expr,
Node *  else_expr 
)

Build a ternary conditional expression node (cond ? then : else).

Parameters
condThe condition expression.
then_exprThe expression evaluated when cond is non-zero.
else_exprThe expression evaluated when cond is zero.
Returns
An NK_COND node.

Convenience wrapper: MakeCond(cond, then_expr, else_expr).

◆ __builtin_ast_const_int_value()

bool __builtin_ast_const_int_value ( Node *  node,
int64_t *  out 
)

Evaluate an integer constant expression node.

Parameters
nodeA node, typically a macro or attribute argument.
outReceives the value when the result is true.
Returns
true if node is an integer constant expression (3, -1, 2 * N, an enum constant), false otherwise.

Convenience wrapper: ConstIntValue(node, &out).

◆ __builtin_ast_const_uint_value()

bool __builtin_ast_const_uint_value ( Node *  node,
uint64_t *  out 
)

Evaluate an unsigned integer constant expression node.

Parameters
nodeA node, typically a macro or attribute argument.
outReceives the value when the result is true.
Returns
true if node is an integer constant expression that is non-negative or of an unsigned type, so a value above INT64_MAX such as 18446744073709551615ULL is accepted.

Convenience wrapper: ConstUIntValue(node, &out).

◆ __builtin_ast_copy_location()

Node * __builtin_ast_copy_location ( Node *  dst,
Node *  src 
)

Copy the source token from one node to another.

Parameters
dstGenerated node to update.
srcSource node whose location should be reused.
Returns
dst, for chaining.

Convenience wrapper: CopyLocation(dst, src).

◆ __builtin_ast_copy_node()

Node * __builtin_ast_copy_node ( Node *  n)

Deep-copy an expression or statement tree.

Parameters
nNode to copy.
Returns
A new node that shares no list or child with n, or NULL.

Nodes are linked into a list by the first builtin that takes them; CopyNode builds the separate node a second list needs. The copy has its own loop, switch and user labels, its own cases, and its own locals: declared variables and the temporaries of compound assignments and struct-returning calls (so it needs a function context). A goto to a label outside the copy is bound again by name where the copy lands. Cleanup variables and VLAs get their own handler and size. Static locals and checked-pointer declarations are rejected.

◆ __builtin_ast_current_token()

Token * __builtin_ast_current_token ( void  )

Return the token for the macro invocation currently being executed.

Returns
Opaque token for the active macro call site, or NULL outside macro execution.

Convenience wrapper: CurrentToken().

◆ __builtin_ast_deserialize()

Node * __builtin_ast_deserialize ( Type *  ty,
Node *  buf 
)

Build an expression that reconstructs a ty value from buf, copying each member out of the buffer into a zeroed hidden local (the mirror of Serialize). buf needs no particular alignment.

◆ __builtin_ast_do_while()

Node * __builtin_ast_do_while ( Node *  body,
Node *  cond 
)

Create a do-while loop node.

Parameters
bodyThe loop body, or NULL to attach one later with LoopSetBody.
condThe loop condition (tested after each iteration).
Returns
A NK_DO node, or NULL on error.

Convenience wrapper: MakeDoWhile(body, cond). See MakeWhile for break/continue target details.

◆ __builtin_ast_enum_add_constant()

void __builtin_ast_enum_add_constant ( Type *  ty,
const char *  name,
int64_t  value 
)

Add a named constant to an enum type and expose it in scope.

Parameters
tyThe enum type.
nameThe constant name.
valueThe constant integer value.

The constant is appended to ty->enum_constants and also pushed into the current scope so it is usable as an integer constant in subsequently compiled code. Convenience wrapper: EnumAddConstant(ty, name, value).

◆ __builtin_ast_enum_add_current_constant()

void __builtin_ast_enum_add_current_constant ( const char *  name,
int  value 
)

◆ __builtin_ast_enum_at()

EnumConstant * __builtin_ast_enum_at ( Type *  enum_type,
int  index 
)

Return the enum constant at a given index.

Parameters
enum_typeThe enum type to inspect.
indexZero-based index.
Returns
The EnumConstant*, or NULL on out-of-range or non-enum.

Convenience wrapper: EnumAt(ty, index).

◆ __builtin_ast_enum_constant_name()

const char * __builtin_ast_enum_constant_name ( EnumConstant *  ec)

Return the name of an enum constant.

Parameters
ecThe enum constant.
Returns
A NUL-terminated string owned by ec.

Convenience wrapper: EnumConstantName(ec).

◆ __builtin_ast_enum_constant_value()

int64_t __builtin_ast_enum_constant_value ( EnumConstant *  ec)

Return the integer value of an enum constant.

Parameters
ecThe enum constant.
Returns
The constant's integer value (int64_t to support C23 wide underlying types).

Convenience wrapper: EnumConstantValue(ec).

◆ __builtin_ast_enum_count()

int __builtin_ast_enum_count ( Type *  enum_type)

Return the number of constants in an enum type.

Parameters
enum_typeThe enum type to inspect.
Returns
The constant count, or -1 if enum_type is not an enum.

Convenience wrapper: EnumCount(ty).

◆ __builtin_ast_enum_find()

EnumConstant * __builtin_ast_enum_find ( Type *  enum_type,
const char *  name 
)

Look up an enum constant by name.

Parameters
enum_typeThe enum type to search.
nameThe constant name to look up.
Returns
The matching EnumConstant*, or NULL if not found.

Convenience wrapper: EnumFind(ty, name).

◆ __builtin_ast_enum_from_string_chain()

Node * __builtin_ast_enum_from_string_chain ( Type *  ty,
Node *  expr 
)

Build a block of if (strcmp(expr, "Name0") == 0) return V0; ... return -1; over the constants of an enum type.

Parameters
tyThe enum type.
exprThe expression to compare (a const char *).
Returns
An NK_BLOCK node. Caller wraps it in a function returning the enum type (or an int).

Convenience wrapper: EnumFromString(ty, expr).

◆ __builtin_ast_enum_name()

const char * __builtin_ast_enum_name ( Type *  e)

Return the tag name of an enum type.

Parameters
eThe enum type to inspect.
Returns
A NUL-terminated string owned by e.

Convenience wrapper: EnumName(ty).

◆ __builtin_ast_enum_to_string_switch()

Node * __builtin_ast_enum_to_string_switch ( Type *  ty,
Node *  expr 
)

Build a switch (expr) { case V0: return "Name0"; ... default: return ""; } over the constants of an enum type.

Parameters
tyThe enum type.
exprThe expression to switch on (the enum value).
Returns
An NK_SWITCH node. Caller wraps it in a function returning const char *.

Convenience wrapper: EnumToString(ty, expr).

◆ __builtin_ast_enum_value()

int64_t __builtin_ast_enum_value ( Type *  e,
int  index 
)

Return the integer value of the enum constant at the given index.

Parameters
eThe enum type to inspect.
indexZero-based index.
Returns
The constant's integer value (int64_t), or -1 on out-of-range.

Convenience wrapper: EnumValue(ty, index).

◆ __builtin_ast_enum_value_count()

int __builtin_ast_enum_value_count ( Type *  e)

Return the number of values in an enum type.

Parameters
eThe enum type to inspect.
Returns
The constant count, or -1 if e is not an enum.

Convenience wrapper: EnumValueCount(ty).

◆ __builtin_ast_enum_value_name()

const char * __builtin_ast_enum_value_name ( Type *  e,
int  index 
)

Return the name of the enum constant at the given index.

Parameters
eThe enum type to inspect.
indexZero-based index.
Returns
A NUL-terminated string, or NULL on out-of-range.

Convenience wrapper: EnumValueName(ty, index).

◆ __builtin_ast_expr_stmt()

Node * __builtin_ast_expr_stmt ( Node *  expr)

Build an expression statement node.

Parameters
exprThe expression to evaluate for side effects.
Returns
An NK_EXPR_STMT node.

Convenience wrapper: MakeExprStmt(expr).

◆ __builtin_ast_fence_is_signal()

bool __builtin_ast_fence_is_signal ( Node *  node)

Return whether an NK_FENCE is a signal fence.

Parameters
nodeAn NK_FENCE node.
Returns
True for a signal fence, false for a thread fence or other kinds.

Convenience wrapper: FenceIsSignal(node).

◆ __builtin_ast_find_global()

Obj * __builtin_ast_find_global ( const char *  name)

Look up a global symbol by name.

Parameters
nameThe global name to look up.
Returns
The matching Obj*, or NULL if not found.

Convenience wrapper: FindGlobal(name).

◆ __builtin_ast_find_type()

Type * __builtin_ast_find_type ( const char *  name)

Look up a type by tag name (struct/union/enum).

Parameters
nameThe tag name to look up.
Returns
The matching Type*, or NULL if not found.

Convenience wrapper: FindType(name).

◆ __builtin_ast_float_literal()

Node * __builtin_ast_float_literal ( double  value)

Build a floating-point literal AST node.

Parameters
valueThe floating-point value.
Returns
An NK_NUM node for value.

Convenience wrapper: MakeFloatLiteral(value).

◆ __builtin_ast_for()

Node * __builtin_ast_for ( Node *  init,
Node *  cond,
Node *  inc,
Node *  body 
)

Create a for loop node.

Parameters
initInitialiser expression/statement (may be NULL).
condLoop condition (may be NULL for infinite loop).
incIncrement expression (may be NULL).
bodyLoop body, or NULL to attach one later with LoopSetBody.
Returns
A NK_FOR node, or NULL on error.

Convenience wrapper: MakeFor(init, cond, inc, body). See MakeWhile for break/continue target details – note only body gets loop-context treatment, not init/cond/inc.

◆ __builtin_ast_funcall()

Node * __builtin_ast_funcall ( Node *  callee,
Node **  args,
int  n 
)

Create a function call node.

Parameters
calleeAn expression node that evaluates to a function (or function pointer). The callee's lhs field holds this expression.
argsArray of argument nodes (may be NULL if n == 0).
nNumber of arguments.
Returns
A NK_FUNCALL node, or NULL on error.

Convenience wrapper: MakeFuncCall(callee, args, n).

◆ __builtin_ast_function()

Obj * __builtin_ast_function ( const char *  name,
Type *  return_type 
)

Create a new function object.

Parameters
nameThe function name.
return_typeThe return type.
Returns
The newly created function object, or NULL on error.

The function is automatically added to the globals list and will be compiled when the main program is compiled. Convenience wrapper: MakeFunction(name, return_type).

◆ __builtin_ast_function_add_param()

void __builtin_ast_function_add_param ( Obj *  fn,
const char *  name,
Type *  type 
)

Add a parameter to a function.

Parameters
fnThe function object.
nameThe parameter name.
typeThe parameter type.

Parameters are added in order. Call this multiple times for multiple parameters. Convenience wrapper: FunctionAddParam(fn, name, type).

◆ __builtin_ast_function_body()

Node * __builtin_ast_function_body ( Obj *  fn)

Return the top-level block of a function definition.

Parameters
fnA function Obj.
Returns
The body NK_BLOCK, or NULL for a declaration or a non-function.

Convenience wrapper: FnBody(fn).

◆ __builtin_ast_function_local_at()

Obj * __builtin_ast_function_local_at ( Obj *  fn,
int  index 
)

Return a local variable of a function definition, in declaration order.

Parameters
fnA function Obj.
indexZero-based local index.
Returns
The local Obj, or NULL when out of range.

Convenience wrapper: FnLocalAt(fn, i).

◆ __builtin_ast_function_local_count()

int __builtin_ast_function_local_count ( Obj *  fn)

Return the number of source-level locals of a function definition.

Parameters
fnA function Obj.
Returns
The local count; parameters and compiler temporaries are excluded.

Convenience wrapper: FnLocalCount(fn).

◆ __builtin_ast_function_param_at()

Obj * __builtin_ast_function_param_at ( Obj *  fn,
int  index 
)

Return a parameter of a function definition, in declaration order.

Parameters
fnA function Obj.
indexZero-based parameter index.
Returns
The parameter Obj (name and type), or NULL when out of range.

Convenience wrapper: FnParamAt(fn, i).

◆ __builtin_ast_function_param_count()

int __builtin_ast_function_param_count ( Obj *  fn)

Return the number of parameters of a function definition.

Parameters
fnA function Obj.
Returns
The parameter count, 0 for a declaration.

Convenience wrapper: FnParamCount(fn).

◆ __builtin_ast_function_prototype()

Obj * __builtin_ast_function_prototype ( const char *  name,
Type *  return_type 
)

Create a function forward declaration (prototype) without a body.

Parameters
nameThe function name.
return_typeThe return type.
Returns
The declaration Obj*, or NULL on error.

Use FunctionAddParam to add parameters and PublishNode to expose it in scope. A subsequent MakeFunction call with the same name will reuse this Obj and fill in the body. Convenience wrapper: FunctionPrototype(name, return_type).

◆ __builtin_ast_function_set_body()

void __builtin_ast_function_set_body ( Obj *  fn,
Node *  body 
)

Set the body of a function.

Parameters
fnThe function object.
bodyThe function body (a statement or block node).

If body is not already a NK_BLOCK, it will be wrapped in one. Convenience wrapper: FunctionSetBody(fn, body).

◆ __builtin_ast_function_set_inline()

void __builtin_ast_function_set_inline ( Obj *  fn,
bool  is_inline 
)

Set whether a function is inline.

Parameters
fnThe function object.
is_inlineTrue for inline, false otherwise.

Convenience wrapper: FunctionSetInline(fn, is_inline).

◆ __builtin_ast_function_set_static()

void __builtin_ast_function_set_static ( Obj *  fn,
bool  is_static 
)

Set whether a function has static linkage.

Parameters
fnThe function object.
is_staticTrue for static linkage, false for external.

Convenience wrapper: FunctionSetStatic(fn, is_static).

◆ __builtin_ast_function_set_variadic()

void __builtin_ast_function_set_variadic ( Obj *  fn,
bool  is_variadic 
)

Set whether a function is variadic.

Parameters
fnThe function object.
is_variadicTrue for variadic, false otherwise.

Convenience wrapper: FunctionSetVariadic(fn, is_variadic).

◆ __builtin_ast_get_type()

Type * __builtin_ast_get_type ( const char *  name)

Look up a type by name, resolving standard base-type spellings.

Parameters
nameThe type name to look up. Any standard base-type spelling is accepted regardless of word order: "int", "unsigned char", "long long", "signed int", "long double _Complex", "bool", ... Otherwise the name is resolved as a typedef or tag.
Returns
The matching Type*.

An unresolved name is a hard comptime error, since the result normally flows straight into MakeArray()/MakeConst()/GlobalVar(). Use FindType(name) or TypeExists(name) to probe for an optional type without erroring. Convenience wrapper: GetType(name).

◆ __builtin_ast_global_at()

Obj * __builtin_ast_global_at ( int  index)

Return the global symbol at the given index.

Parameters
indexZero-based global index.
Returns
The Obj* at the given slot, or NULL on out-of-range.

Convenience wrapper: GlobalAt(index).

◆ __builtin_ast_global_count()

int __builtin_ast_global_count ( void  )

Return the total number of global symbols.

Returns
The count of globals.

Convenience wrapper: GlobalCount().

◆ __builtin_ast_global_var()

Obj * __builtin_ast_global_var ( const char *  name,
Type *  ty 
)

Create a new named global variable definition.

Parameters
nameThe variable name (must be unique among globals).
tyThe variable type. Use MakeArray(char_ty, len) for byte arrays so that the size matches the init_data length.
Returns
The new Obj*, or NULL on error.

The variable is registered in vm->compiler.globals. For inline macros the capture loop will stash it in macro_globals and emit an extern declaration into every input file's token stream so the parser can resolve references. Convenience wrapper: GlobalVar(name, ty).

◆ __builtin_ast_global_var_set_init_data()

void __builtin_ast_global_var_set_init_data ( Obj *  var,
const char *  data,
int  len 
)

Set the initial data for a generated global variable.

Parameters
varThe global variable object.
dataPointer to the raw byte data.
lenNumber of bytes to copy. Must equal var->ty->size.

Convenience wrapper: GlobalVarSetInitData(var, data, len).

◆ __builtin_ast_global_var_set_static()

void __builtin_ast_global_var_set_static ( Obj *  var,
bool  is_static 
)

Set the static (internal linkage) flag on a generated global.

Parameters
varThe global variable object.
is_staticTrue for internal linkage (file-scope static).

Convenience wrapper: GlobalVarSetStatic(var, is_static).

◆ __builtin_ast_goto_jump_kind()

int __builtin_ast_goto_jump_kind ( Node *  node)

Return which statement an NK_GOTO came from.

Parameters
nodeThe node to inspect.
Returns
AST_JUMP_GOTO, AST_JUMP_BREAK or AST_JUMP_CONTINUE; 0 for other kinds.

Convenience wrapper: GotoJumpKind(node).

◆ __builtin_ast_if()

Node * __builtin_ast_if ( Node *  cond,
Node *  then_body,
Node *  else_body 
)

Build an if statement node.

Parameters
condThe condition expression.
then_bodyThe body executed when cond is non-zero.
else_bodyThe body executed when cond is zero, or NULL.
Returns
An NK_IF node.

Convenience wrapper: MakeIf(cond, then_body, else_body).

◆ __builtin_ast_init_array()

Node * __builtin_ast_init_array ( Type *  elem_ty,
Node **  elems,
int  n 
)

Build an array compound literal. Element type is explicit to avoid long-inference surprises with MakeIntLiteral.

◆ __builtin_ast_init_struct()

Node * __builtin_ast_init_struct ( Type *  ty,
const char **  fields,
Node **  values,
int  n 
)

Build a designated struct/union initializer. Unmentioned fields are zero-initialised. Partial init (n < member count) is allowed.

◆ __builtin_ast_int_literal()

Node * __builtin_ast_int_literal ( int64_t  value)

Build an integer literal AST node.

Parameters
valueThe integer value.
Returns
An NK_NUM node for value.

Convenience wrapper: MakeIntLiteral(value).

◆ __builtin_ast_label_name()

const char * __builtin_ast_label_name ( Node *  node)

Return the name of an NK_GOTO, NK_LABEL or NK_LABEL_VAL.

Parameters
nodeThe node to inspect.
Returns
The label name, or NULL for other kinds and for break and continue.

Convenience wrapper: LabelName(node).

◆ __builtin_ast_local_var()

Node * __builtin_ast_local_var ( const char *  name,
Type *  ty 
)

Declare a named local variable in the current function scope and return a variable-reference node for it.

Parameters
nameThe variable name (user-visible).
tyThe variable type.
Returns
A NK_VAR node referencing the new local, or NULL if called outside a function body or on invalid arguments.
Note
The variable is injected into the current function's locals list and will receive a stack offset when the function is compiled. For temporaries that must not capture user names, prefer __builtin_ast_local_var_unique().

Convenience wrapper: MakeLocalVar(name, ty).

◆ __builtin_ast_local_var_unique()

Node * __builtin_ast_local_var_unique ( Type *  ty)

Declare a hygienic (gensym'd) local variable in the current function scope and return a variable-reference node for it.

Parameters
tyThe variable type.
Returns
A NK_VAR node referencing the new local, or NULL on error.
Note
The generated name begins with ".L.." and is therefore not expressible as a user identifier — guaranteed no name capture. This is the safe default for macro temporaries.

Convenience wrapper: MakeLocalVarUnique(ty).

◆ __builtin_ast_loop_set_body()

Node * __builtin_ast_loop_set_body ( Node *  loop,
Node *  body 
)

Attach body to loop (a node from MakeWhile/MakeFor/MakeDoWhile).

Parameters
loopThe loop node to attach the body to.
bodyThe loop body statement; a QuoteLazy() fragment is expanded in loop's own context.
Returns
loop, for chaining.

Convenience wrapper: LoopSetBody(loop, body). Typically called inside a WithLoop(loop) { ... } block so an eager Quote("break;")/Quote("continue;") call building body resolves against loop.

◆ __builtin_ast_macro_call_arg_at()

Node * __builtin_ast_macro_call_arg_at ( Node *  node,
int  index 
)

Return an argument of an NK_MACRO_CALL.

Parameters
nodeThe node to inspect.
indexZero-based argument index.
Returns
The argument, or NULL when out of range.

Convenience wrapper: MacroCallArgAt(node, i).

◆ __builtin_ast_macro_call_arg_count()

int __builtin_ast_macro_call_arg_count ( Node *  node)

Return the argument count of an NK_MACRO_CALL.

Parameters
nodeThe node to inspect.
Returns
The count, 0 for other kinds.

Convenience wrapper: MacroCallArgCount(node).

◆ __builtin_ast_macro_call_name()

const char * __builtin_ast_macro_call_name ( Node *  node)

Return the macro name of a not-yet-expanded NK_MACRO_CALL.

Parameters
nodeThe node to inspect.
Returns
The name, or NULL for other kinds.

Convenience wrapper: MacroCallName(node).

◆ __builtin_ast_make_array()

Type * __builtin_ast_make_array ( Type *  base,
int  length 
)

Build a fixed-length array type.

Parameters
baseThe element type.
lengthThe element count.
Returns
A Type* representing "base[length]", or NULL on error.

Convenience wrapper: MakeArray(base, length).

◆ __builtin_ast_make_const()

Type * __builtin_ast_make_const ( Type *  ty)

Return a const-qualified copy of ty.

Parameters
tyThe type to qualify.
Returns
A const-qualified Type*, or NULL on error.

Convenience wrapper: MakeConst(ty).

◆ __builtin_ast_make_enum()

Type * __builtin_ast_make_enum ( const char *  name)

Create and expose a new named enum type.

Parameters
nameThe enum tag name.
Returns
The new enum Type*, or NULL on error.

Use EnumAddConstant to add constants after creation. Convenience wrapper: MakeEnum(name).

◆ __builtin_ast_make_func_ptr_type()

Type * __builtin_ast_make_func_ptr_type ( Type *  return_ty,
Type **  param_types,
int  nparams 
)

Build a pointer-to-function type, e.g. "T (*)(T)".

Parameters
return_tyThe function's return type.
param_typesArray of parameter types (each copy_type()'d internally).
nparamsNumber of entries in param_types (max 16).
Returns
A Type* representing "return_ty (*)(param_types...)", or NULL on error.

Convenience wrapper: MakeFuncPtrType(return_ty, param_types, nparams).

◆ __builtin_ast_make_pointer()

Type * __builtin_ast_make_pointer ( Type *  base)

Build a pointer-to-base type.

Parameters
baseThe pointed-to type.
Returns
A Type* representing "base *", or NULL on error.

Convenience wrapper: MakePointer(base).

◆ __builtin_ast_make_struct()

Type * __builtin_ast_make_struct ( const char *  name)

Create and expose a new named struct type.

Parameters
nameThe struct tag name.
Returns
The new Type*, or NULL on error.

Use StructAddField to add fields after creation. The type is immediately visible via FindType(name). Convenience wrapper: MakeStruct(name).

◆ __builtin_ast_make_typedef()

Type * __builtin_ast_make_typedef ( const char *  name,
Type *  underlying 
)

Register a typedef alias for a type and expose it in scope.

Parameters
nameThe typedef name.
underlyingThe aliased type.
Returns
The aliased type after registration, or NULL on invalid arguments.

After this call, FindType(name) resolves to underlying and subsequently compiled code can use name as a type name. Convenience wrapper: MakeTypedef(name, underlying).

◆ __builtin_ast_make_union()

Type * __builtin_ast_make_union ( const char *  name)

Create and expose a new named union type.

Parameters
nameThe union tag name.
Returns
The new union Type*, or NULL on error.

Convenience wrapper: MakeUnion(name).

◆ __builtin_ast_make_volatile()

Type * __builtin_ast_make_volatile ( Type *  ty)

Return a volatile-qualified copy of ty.

Parameters
tyThe type to qualify.
Returns
A volatile-qualified Type*, or NULL on error.

Convenience wrapper: MakeVolatile(ty).

◆ __builtin_ast_member()

Node * __builtin_ast_member ( Node *  obj,
const char *  name 
)

Create a struct/union member access node (obj.name).

Parameters
objAn expression node whose type must be a struct or union.
nameThe member name as a NUL-terminated string.
Returns
A NK_MEMBER node, or NULL if the member is not found or obj is not a struct/union type.
Note
The callee is responsible for dereferencing pointers first; pass the struct value directly (use __builtin_ast_unary(NK_DEREF,…) for pointer-to-struct access).

Convenience wrapper: MakeMember(obj, name).

◆ __builtin_ast_member_attr_arg()

Node * __builtin_ast_member_attr_arg ( Member *  m,
const char *  name,
int  index 
)

Return argument index of the member's first use of name, or NULL.

◆ __builtin_ast_member_attr_arg_at()

Node * __builtin_ast_member_attr_arg_at ( Member *  m,
int  index,
int  arg 
)

Return argument arg of the member's attribute use index, or NULL.

◆ __builtin_ast_member_attr_arg_count()

int __builtin_ast_member_attr_arg_count ( Member *  m,
const char *  name 
)

Return the argument count of the member's first use of name, or -1 when absent.

◆ __builtin_ast_member_attr_arg_count_at()

int __builtin_ast_member_attr_arg_count_at ( Member *  m,
int  index 
)

Return the argument count of the member's attribute use index, or -1.

◆ __builtin_ast_member_attr_count()

int __builtin_ast_member_attr_count ( Member *  m)

Return the number of custom attribute uses on the member.

◆ __builtin_ast_member_attr_name_at()

const char * __builtin_ast_member_attr_name_at ( Member *  m,
int  index 
)

Return the name of the member's attribute use index, or NULL.

◆ __builtin_ast_member_bitfield_width()

int __builtin_ast_member_bitfield_width ( Member *  m)

Return the bit width of a bitfield member.

Parameters
mThe member to inspect.
Returns
The bit width for bitfield members, 0 otherwise.

Convenience wrapper: MemberBitfieldWidth(m).

◆ __builtin_ast_member_has_attr()

int __builtin_ast_member_has_attr ( Member *  m,
const char *  name 
)

Return 1 if the member carries the custom attribute name.

◆ __builtin_ast_member_is_bitfield()

bool __builtin_ast_member_is_bitfield ( Member *  m)

Test whether a member is a bitfield.

Parameters
mThe member to inspect.
Returns
True if the member is a bitfield, false otherwise.

Convenience wrapper: MemberIsBitfield(m).

◆ __builtin_ast_member_name()

const char * __builtin_ast_member_name ( Member *  m)

Return the name of a struct/union member.

Parameters
mThe member to inspect.
Returns
A NUL-terminated string owned by m.

Convenience wrapper: MemberName(m).

◆ __builtin_ast_member_offset()

int __builtin_ast_member_offset ( Member *  m)

Return the byte offset of a struct/union member.

Parameters
mThe member to inspect.
Returns
The offset in bytes.

Convenience wrapper: MemberOffset(m).

◆ __builtin_ast_member_type()

Type * __builtin_ast_member_type ( Member *  m)

Return the type of a struct/union member.

Parameters
mThe member to inspect.
Returns
The member's Type*.

Convenience wrapper: MemberType(m).

◆ __builtin_ast_node_body()

Node * __builtin_ast_node_body ( Node *  node)

Return the statement list of an NK_BLOCK or NK_STMT_EXPR.

Parameters
nodeThe node to inspect.
Returns
The first statement, or NULL. For for/while/do the body is NodeThen.

Convenience wrapper: NodeBody(node).

◆ __builtin_ast_node_cond()

Node * __builtin_ast_node_cond ( Node *  node)

Return the condition of an if, loop, switch or ?: node.

Parameters
nodeThe node to inspect.
Returns
The condition, or NULL.

Convenience wrapper: NodeCond(node).

◆ __builtin_ast_node_else()

Node * __builtin_ast_node_else ( Node *  node)

Return the else-branch of an if or ?: node.

Parameters
nodeThe node to inspect.
Returns
The branch, or NULL.

Convenience wrapper: NodeElse(node).

◆ __builtin_ast_node_float_value()

double __builtin_ast_node_float_value ( Node *  node)

Return the value of a floating NK_NUM literal.

Parameters
nodeThe node to inspect.
Returns
The value, 0 for other kinds.

Convenience wrapper: NodeFloatValue(node).

◆ __builtin_ast_node_inc()

Node * __builtin_ast_node_inc ( Node *  node)

Return the increment of a for node.

Parameters
nodeThe node to inspect.
Returns
The increment, or NULL.

Convenience wrapper: NodeInc(node).

◆ __builtin_ast_node_init()

Node * __builtin_ast_node_init ( Node *  node)

Return the initialiser of a for node.

Parameters
nodeThe node to inspect.
Returns
The initialiser, or NULL.

Convenience wrapper: NodeInit(node).

◆ __builtin_ast_node_int_value()

long long __builtin_ast_node_int_value ( Node *  node)

Return the value of an integer NK_NUM literal.

Parameters
nodeThe node to inspect.
Returns
The value, 0 for other kinds.

Convenience wrapper: NodeIntValue(node).

◆ __builtin_ast_node_kind()

NodeKind __builtin_ast_node_kind ( Node *  node)

Return the kind of a node.

Parameters
nodeThe node to inspect.
Returns
The NodeKind, or NK_NULL_EXPR for NULL.

Convenience wrapper: GetNodeKind(node).

◆ __builtin_ast_node_lhs()

Node * __builtin_ast_node_lhs ( Node *  node)

Return the left operand (or sole operand) of a node.

Parameters
nodeThe node to inspect.
Returns
The operand, or NULL when the kind has none.

Convenience wrapper: NodeLhs(node).

◆ __builtin_ast_node_member()

Member * __builtin_ast_node_member ( Node *  node)

Return the member an NK_MEMBER node selects.

Parameters
nodeThe node to inspect.
Returns
The Member, or NULL.

Convenience wrapper: NodeMember(node).

◆ __builtin_ast_node_next()

Node * __builtin_ast_node_next ( Node *  node)

Return the next node in a statement or argument list.

Parameters
nodeThe node to inspect.
Returns
The next sibling, or NULL at the end.

Convenience wrapper: NodeNext(node).

◆ __builtin_ast_node_rhs()

Node * __builtin_ast_node_rhs ( Node *  node)

Return the right operand of a node.

Parameters
nodeThe node to inspect.
Returns
The operand, or NULL when the kind has none.

Convenience wrapper: NodeRhs(node).

◆ __builtin_ast_node_strip_implicit()

Node * __builtin_ast_node_strip_implicit ( Node *  node)

Peel compiler-inserted casts and call wrappers off a node.

Parameters
nodeThe node to inspect.
Returns
The first node that is not an implicit cast or call wrapper. Explicit (T)x casts stay.

Convenience wrapper: StripImplicit(node).

◆ __builtin_ast_node_then()

Node * __builtin_ast_node_then ( Node *  node)

Return the then-branch of an if or ?: node, or the body of a loop or switch.

Parameters
nodeThe node to inspect.
Returns
The branch, or NULL.

Convenience wrapper: NodeThen(node).

◆ __builtin_ast_node_type()

Type * __builtin_ast_node_type ( Node *  node)

Return the resolved type of an expression node.

Parameters
nodeThe node to inspect.
Returns
The Type*, or NULL for statements and untyped nodes.

Convenience wrapper: GetNodeType(node).

◆ __builtin_ast_node_var_obj()

Obj * __builtin_ast_node_var_obj ( Node *  node)

Return the variable an NK_VAR (or NK_MEMZERO) node refers to.

Parameters
nodeThe node to inspect.
Returns
The Obj, or NULL.

Convenience wrapper: NodeVarObj(node).

◆ __builtin_ast_null()

Node * __builtin_ast_null ( void  )

Build a typed null pointer node: (void *)0.

Returns
An NK_NUM node representing a typed NULL.

Convenience wrapper: MakeNull().

◆ __builtin_ast_obj_is_definition()

bool __builtin_ast_obj_is_definition ( Obj *  obj)

Test whether a global object has a definition.

Parameters
objThe object to inspect.
Returns
True for defined objects, false for declarations only.

Convenience wrapper: ObjIsDefinition(obj).

◆ __builtin_ast_obj_is_function()

bool __builtin_ast_obj_is_function ( Obj *  obj)

Test whether a global object is a function.

Parameters
objThe object to inspect.
Returns
True for functions, false for variables.

Convenience wrapper: ObjIsFunction(obj).

◆ __builtin_ast_obj_is_static()

bool __builtin_ast_obj_is_static ( Obj *  obj)

Test whether a global object has internal (static) linkage.

Parameters
objThe object to inspect.
Returns
True for static linkage, false for external.

Convenience wrapper: ObjIsStatic(obj).

◆ __builtin_ast_obj_name()

const char * __builtin_ast_obj_name ( Obj *  obj)

Return the name of a global object.

Parameters
objThe object to inspect.
Returns
A NUL-terminated string owned by obj.

Convenience wrapper: ObjName(obj).

◆ __builtin_ast_obj_next()

Obj * __builtin_ast_obj_next ( Obj *  obj)

Return the next Obj in the list that holds obj.

Parameters
objA parameter, local or global Obj.
Returns
The next Obj, or NULL at the end.

Convenience wrapper: ObjNext(obj).

◆ __builtin_ast_obj_type()

Type * __builtin_ast_obj_type ( Obj *  obj)

Return the type of a global object.

Parameters
objThe object to inspect.
Returns
The object's Type*.

Convenience wrapper: ObjType(obj).

◆ __builtin_ast_offsetof_chain()

int64_t __builtin_ast_offsetof_chain ( Type *  ty,
const char **  names,
int  n 
)

Compute the byte offset of a (possibly nested) member chain.

Parameters
tyThe starting struct/union type.
namesAn array of member names to walk, innermost last.
nThe number of names in the chain.
Returns
The summed byte offset, or -1 if any name cannot be resolved.

Convenience wrapper: OffsetofChain(ty, "a", "b", ...).

◆ __builtin_ast_overflow_op()

int __builtin_ast_overflow_op ( Node *  node)

Return the operation of an NK_OVERFLOW_ARITH.

Parameters
nodeAn NK_OVERFLOW_ARITH node.
Returns
An AST_OVERFLOW_* value, 0 for other kinds.

Convenience wrapper: OverflowOp(node).

◆ __builtin_ast_overflow_result_ptr()

Node * __builtin_ast_overflow_result_ptr ( Node *  node)

Return the result pointer of an NK_OVERFLOW_ARITH.

Parameters
nodeAn NK_OVERFLOW_ARITH node.
Returns
The expression the result is stored through, or NULL for other kinds. The operands are NodeLhs and NodeRhs.

Convenience wrapper: OverflowResultPtr(node).

◆ __builtin_ast_param_attr_arg()

Node * __builtin_ast_param_attr_arg ( Type *  p,
const char *  name,
int  index 
)

Return argument index of the parameter's first use of name, or NULL.

◆ __builtin_ast_param_attr_arg_at()

Node * __builtin_ast_param_attr_arg_at ( Type *  p,
int  index,
int  arg 
)

Return argument arg of the parameter's attribute use index, or NULL.

◆ __builtin_ast_param_attr_arg_count()

int __builtin_ast_param_attr_arg_count ( Type *  p,
const char *  name 
)

Return the argument count of the parameter's first use of name, or -1 when absent.

◆ __builtin_ast_param_attr_arg_count_at()

int __builtin_ast_param_attr_arg_count_at ( Type *  p,
int  index 
)

Return the argument count of the parameter's attribute use index, or -1.

◆ __builtin_ast_param_attr_count()

int __builtin_ast_param_attr_count ( Type *  p)

Return the number of custom attribute uses on the parameter.

◆ __builtin_ast_param_attr_name_at()

const char * __builtin_ast_param_attr_name_at ( Type *  p,
int  index 
)

Return the name of the parameter's attribute use index, or NULL.

◆ __builtin_ast_param_has_attr()

int __builtin_ast_param_has_attr ( Type *  p,
const char *  name 
)

Return 1 if the parameter type p carries the custom attribute name. p comes from TypeParamAt() on the function type.

◆ __builtin_ast_param_ref()

Node * __builtin_ast_param_ref ( Obj *  fn,
const char *  name 
)

Build a reference to a function parameter by name.

Parameters
fnThe function object whose parameter is being referenced.
nameThe parameter name.
Returns
An NK_VAR node for the named parameter.

Use this when building function bodies to reference parameters by name. Convenience wrapper: MakeParamRef(fn, name).

◆ __builtin_ast_pop_block()

void __builtin_ast_pop_block ( void  )

◆ __builtin_ast_pop_enum()

void __builtin_ast_pop_enum ( void  )

◆ __builtin_ast_pop_fn()

void __builtin_ast_pop_fn ( void  )

Restore the function context saved by the most recent push.

Inverse of __builtin_ast_push_fn; typically used through the WithFn(fn) { ... } block helper, which performs the matching pop even on early exit.

◆ __builtin_ast_pop_loop()

void __builtin_ast_pop_loop ( void  )

Restore the loop context saved by the most recent push.

Inverse of __builtin_ast_push_loop; typically used through the WithLoop(loop) { ... } block helper, which performs the matching pop even on early exit.

◆ __builtin_ast_pop_struct()

void __builtin_ast_pop_struct ( void  )

◆ __builtin_ast_pop_switch()

void __builtin_ast_pop_switch ( void  )

◆ __builtin_ast_publish()

Node * __builtin_ast_publish ( Obj *  obj,
Token *  tok 
)

Make a generated object visible at the current source position.

Parameters
objA function or global variable object created by the AST builders.
tokOptional representative token for diagnostics, or NULL.
Returns
A no-op Node on success, or NULL on invalid arguments.

Top-level explicit macro calls run at their source position. Call this after creating a function or global variable when later macro-generated code at the same parse point should be able to reference it without a handwritten declaration. Convenience wrapper: PublishNode(obj) / PublishNodeAt(obj, tok).

◆ __builtin_ast_publish_type()

Node * __builtin_ast_publish_type ( Type *  ty,
Token *  tok 
)

Accept a generated type declaration as already published.

Parameters
tyA type created by MakeStruct, MakeUnion, MakeEnum, or MakeTypedef.
tokOptional representative token for diagnostics, or NULL.
Returns
A no-op Node on success, or NULL on invalid arguments.

Generated type builders self-register in tag or typedef scope. This function lets PublishNode(type) be used uniformly; there is no separate convenience macro for this entry point.

◆ __builtin_ast_push_block()

void __builtin_ast_push_block ( Node *  block)

Establish a block as the current statement-append context.

Parameters
blockThe NK_BLOCK node being populated.

Use with WithBlock(block) so BlockAddStmt(stmt) appends to block without repeating the block pointer.

◆ __builtin_ast_push_enum()

void __builtin_ast_push_enum ( Type *  ty)

Establish an enum as the current constant-add context.

Parameters
tyThe enum type being populated.

Use with WithEnum(ty) so EnumAddConstant(name, value) appends to the current enum.

◆ __builtin_ast_push_fn()

void __builtin_ast_push_fn ( Obj *  fn)

Establish fn as the "function currently being built" so that Quote("return x;") applies the correct implicit return-type cast.

Parameters
fnThe generated function whose return type should be used.

Call __builtin_ast_pop_fn (or use the WithFn macro) to restore the previous context. execute_pragma_macro always restores current_fn after the macro returns, so unmatched pushes cannot leak into the main parse/codegen pass. There is no 1:1 convenience macro; use the WithFn(fn) { ... } block helper to bracket push/pop pairs in a macro body.

◆ __builtin_ast_push_loop()

void __builtin_ast_push_loop ( Node *  loop)

Establish loop as the current loop context, so an eagerly-parsed Quote("break;")/Quote("continue;") call made while it is active resolves against loop's own break/continue targets.

Parameters
loopA loop node returned by MakeWhile/MakeFor/MakeDoWhile.

Call __builtin_ast_pop_loop (or use the WithLoop macro) to restore the previous loop context. Needed only for an eager Quote() body passed to LoopSetBody – MakeWhile/MakeFor/ MakeDoWhile already expand a QuoteLazy() body argument under the new loop's own context without this.

◆ __builtin_ast_push_struct()

void __builtin_ast_push_struct ( Type *  ty)

Establish a struct or union as the current field-add context.

Parameters
tyThe aggregate type being populated.

Use with WithStruct(ty) so StructAddField(name, ty) appends to the current aggregate.

◆ __builtin_ast_push_switch()

void __builtin_ast_push_switch ( Node *  switch_node)

Establish a switch node as the current case/default context.

Parameters
switch_nodeThe switch node being populated.

Use with WithSwitch(sw) so SwitchAddCase(value, body) and SwitchSetDefault(body) append to the current switch.

◆ __builtin_ast_return()

Node * __builtin_ast_return ( Node *  expr)

Build a return statement node.

Parameters
exprThe value to return (may be NULL for return; in void functions).
Returns
An NK_RETURN node.

Convenience wrapper: MakeReturn(expr).

◆ __builtin_ast_serialize()

Node * __builtin_ast_serialize ( Type *  ty,
Node *  expr,
Node *  buf 
)

Build a block of memcpy() calls copying expr (of type ty) into buf (a void or char pointer). Struct/union types are copied member-by-member at their natural offsets, recursing into nested structs; bit-fields copy the bytes holding their bits; scalar types are copied in one memcpy. buf needs no particular alignment.

Note
V1 placeholder: pointer-typed members are copied as raw pointer bytes, not followed.

◆ __builtin_ast_set_token()

Node * __builtin_ast_set_token ( Node *  node,
Token *  tok 
)

Attach an opaque source token to a node.

Parameters
nodeNode to update.
tokToken from __builtin_ast_current_token(), __builtin_ast_synthetic_token(), or __builtin_ast_token_from_node().
Returns
node, for chaining.

Convenience wrapper: SetToken(node, tok).

◆ __builtin_ast_sizeof_expr()

Node * __builtin_ast_sizeof_expr ( Node *  expr)

Emit sizeof(expr): resolve the expression's type then its size.

Parameters
exprThe expression whose type to measure.
Returns
An NK_NUM node holding sizeof(expr).

Convenience wrapper: MakeSizeofExpr(expr).

◆ __builtin_ast_sizeof_type()

Node * __builtin_ast_sizeof_type ( Type *  ty)

Emit sizeof(ty) as a compile-time integer literal.

Parameters
tyThe type to measure.
Returns
An NK_NUM node holding sizeof(ty).

Convenience wrapper: MakeSizeofType(ty).

◆ __builtin_ast_string_literal()

Node * __builtin_ast_string_literal ( const char *  str)

Build a string literal AST node.

Parameters
strA NUL-terminated string.
Returns
An NK_NUM string-literal node.

Convenience wrapper: MakeStringLiteral(str).

◆ __builtin_ast_string_literal_value()

const char * __builtin_ast_string_literal_value ( Node *  node)

Return the text of a string literal node.

Parameters
nodeA node, typically a macro or attribute argument.
Returns
The NUL-terminated string, or NULL if node is not a string literal.

Convenience wrapper: StringLiteralValue(node).

◆ __builtin_ast_struct_add_current_field()

Type * __builtin_ast_struct_add_current_field ( const char *  name,
Type *  field_type 
)

◆ __builtin_ast_struct_add_field()

Type * __builtin_ast_struct_add_field ( Type *  ty,
const char *  name,
Type *  field_type 
)

Append a field to a struct or union and recompute its layout.

Parameters
tyThe struct or union type to modify.
nameThe field name.
field_typeThe field's type.
Returns
ty on success, or NULL on error.

For struct types, offsets are recalculated from scratch after each field addition. For union types, all fields stay at offset 0 and the union size is updated to the maximum field size. Convenience wrapper: StructAddField(ty, name, field_type).

◆ __builtin_ast_struct_member_at()

Member * __builtin_ast_struct_member_at ( Type *  struct_type,
int  index 
)

Return the member at the given index.

Parameters
struct_typeThe struct or union type to inspect.
indexZero-based member index.
Returns
The Member*, or NULL on out-of-range or non-aggregate.

Convenience wrapper: StructMemberAt(ty, index).

◆ __builtin_ast_struct_member_count()

int __builtin_ast_struct_member_count ( Type *  struct_type)

Return the number of members of a struct or union type.

Parameters
struct_typeThe struct or union type to inspect.
Returns
The member count, or -1 if struct_type is not a struct/union.

Convenience wrapper: StructMemberCount(ty).

◆ __builtin_ast_struct_member_find()

Member * __builtin_ast_struct_member_find ( Type *  struct_type,
const char *  name 
)

Look up a struct or union member by name.

Parameters
struct_typeThe struct or union type to search.
nameThe member name to look up.
Returns
The matching Member*, or NULL if not found.

Convenience wrapper: StructMemberFind(ty, name).

◆ __builtin_ast_subscript()

Node * __builtin_ast_subscript ( Node *  arr,
Node *  idx 
)

Build an array subscript node: arr[idx], desugared as *(arr+idx).

Parameters
arrThe array (or pointer) expression.
idxThe index expression.
Returns
An NK_ADD / NK_DEREF node pair representing the subscript.

Convenience wrapper: MakeSubscript(arr, idx).

◆ __builtin_ast_switch()

Node * __builtin_ast_switch ( Node *  cond)

Build a switch statement node.

Parameters
condThe expression to switch on.
Returns
An NK_SWITCH node. Use __builtin_ast_switch_add_case and __builtin_ast_switch_set_default to populate it.

Convenience wrapper: MakeSwitch(cond).

◆ __builtin_ast_switch_add_case()

void __builtin_ast_switch_add_case ( Node *  switch_node,
Node *  value,
Node *  body 
)

Append a case to a switch statement.

Parameters
switch_nodeThe switch node returned by __builtin_ast_switch.
valueThe case value expression.
bodyThe body statement for this case.

Convenience wrapper: SwitchAddCase(sw, value, body), or SwitchAddCase(value, body) inside WithSwitch(sw).

◆ __builtin_ast_switch_add_current_case()

void __builtin_ast_switch_add_current_case ( Node *  value,
Node *  body 
)

◆ __builtin_ast_switch_case_at()

Node * __builtin_ast_switch_case_at ( Node *  sw,
int  index 
)

Return a case label of a switch, in source order.

Parameters
swAn NK_SWITCH node.
indexZero-based case index.
Returns
An NK_CASE node, or NULL when out of range.

Convenience wrapper: SwitchCaseAt(sw, i).

◆ __builtin_ast_switch_case_count()

int __builtin_ast_switch_case_count ( Node *  sw)

Return the number of case labels of a switch (excluding default).

Parameters
swAn NK_SWITCH node.
Returns
The case count, 0 for other kinds.

Convenience wrapper: SwitchCaseCount(sw).

◆ __builtin_ast_switch_default()

Node * __builtin_ast_switch_default ( Node *  sw)

Return the default label of a switch.

Parameters
swAn NK_SWITCH node.
Returns
The default NK_CASE node, or NULL.

Convenience wrapper: SwitchDefault(sw).

◆ __builtin_ast_switch_set_current_default()

void __builtin_ast_switch_set_current_default ( Node *  body)

◆ __builtin_ast_switch_set_default()

void __builtin_ast_switch_set_default ( Node *  switch_node,
Node *  body 
)

Set the default case for a switch statement.

Parameters
switch_nodeThe switch node returned by __builtin_ast_switch.
bodyThe default-case body statement.

Convenience wrapper: SwitchSetDefault(sw, body), or SwitchSetDefault(body) inside WithSwitch(sw).

◆ __builtin_ast_synthetic_token()

Token * __builtin_ast_synthetic_token ( const char *  label)

Create an opaque synthetic source token for generated AST nodes.

Parameters
labelShort diagnostic label for the synthetic location.
Returns
Arena-allocated synthetic token, or NULL on error.

Use this when a generated node should diagnose against a stable generated location instead of the macro call or an input node. Convenience wrapper: SyntheticToken(label).

◆ __builtin_ast_token_from_node()

Token * __builtin_ast_token_from_node ( Node *  node)

Return the opaque source token attached to a node.

Parameters
nodeNode to inspect.
Returns
The node token, or NULL.

Convenience wrapper: TokenFromNode(node).

◆ __builtin_ast_type_align()

int __builtin_ast_type_align ( Type *  ty)

Return _Alignof(ty) in bytes.

Parameters
tyThe type to inspect.
Returns
The alignment in bytes.

Convenience wrapper: TypeAlign(ty).

◆ __builtin_ast_type_array_len()

int __builtin_ast_type_array_len ( Type *  ty)

Return the fixed length of an array type.

Parameters
tyThe array type to inspect.
Returns
The element count for TY_ARRAY types, -1 otherwise.

Convenience wrapper: TypeArrayLen(ty).

◆ __builtin_ast_type_base()

Type * __builtin_ast_type_base ( Type *  ty)

Return the element type of a pointer or array.

Parameters
tyThe pointer/array type to inspect.
Returns
The base Type*, or NULL if ty is not a pointer or array.

Convenience wrapper: TypeBase(ty).

◆ __builtin_ast_type_c_name()

const char * __builtin_ast_type_c_name ( Type *  ty)

Return a valid C identifier fragment naming ty.

Parameters
tyThe type to inspect.
Returns
TypeName(ty) for named types, or a builtin spelling ("int", "double", "ulong", ...) for builtin scalar types, or NULL.

Convenience wrapper: TypeCName(ty). Intended for naming generated functions, e.g. sum_<T> from GenerateSum(elem_type).

◆ __builtin_ast_type_exists()

bool __builtin_ast_type_exists ( const char *  name)

Check whether a type is currently in scope by name.

Parameters
nameThe type name to look up.
Returns
True if the name resolves to a type, false otherwise.

Convenience wrapper: TypeExists(name).

◆ __builtin_ast_type_is_const()

bool __builtin_ast_type_is_const ( Type *  ty)

Test whether a type is const-qualified.

Parameters
tyThe type to inspect.
Returns
True if ty has a const qualifier, false otherwise.

Convenience wrapper: TypeIsConst(ty).

◆ __builtin_ast_type_is_unsigned()

bool __builtin_ast_type_is_unsigned ( Type *  ty)

Test whether an integer type is unsigned.

Parameters
tyThe type to inspect.
Returns
True for unsigned integer types, false otherwise.

Convenience wrapper: TypeIsUnsigned(ty).

◆ __builtin_ast_type_is_variadic()

bool __builtin_ast_type_is_variadic ( Type *  ty)

Test whether a function type is variadic.

Parameters
tyThe type to inspect.
Returns
True for variadic function types, false otherwise.

Convenience wrapper: TypeIsVariadic(ty).

◆ __builtin_ast_type_kind()

TypeKind __builtin_ast_type_kind ( Type *  ty)

Return the TypeKind tag of a type.

Parameters
tyThe type to inspect.
Returns
The type kind (TK_INT, TK_STRUCT, TK_PTR, ...).

Convenience wrapper: GetTypeKind(ty).

◆ __builtin_ast_type_name()

const char * __builtin_ast_type_name ( Type *  ty)

Return the user-visible name of a type, if any.

Parameters
tyThe type to inspect.
Returns
A freshly-allocated NUL-terminated string, or NULL for anonymous types.

Convenience wrapper: TypeName(ty).

◆ __builtin_ast_type_param_at()

Type * __builtin_ast_type_param_at ( Type *  ty,
int  index 
)

Return the type of the parameter at the given index.

Parameters
tyThe function type to inspect.
indexZero-based parameter index.
Returns
The parameter's Type*, or NULL on out-of-range or non-function ty.

Convenience wrapper: TypeParamAt(ty, index).

◆ __builtin_ast_type_param_count()

int __builtin_ast_type_param_count ( Type *  ty)

Return the number of declared parameters of a function type.

Parameters
tyThe function type to inspect.
Returns
The parameter count for TY_FUNC types, -1 otherwise.

Convenience wrapper: TypeParamCount(ty).

◆ __builtin_ast_type_return_type()

Type * __builtin_ast_type_return_type ( Type *  ty)

Return the return type of a function type.

Parameters
tyThe function type to inspect.
Returns
The return Type*, or NULL if ty is not a function type.

Convenience wrapper: TypeReturnType(ty).

◆ __builtin_ast_type_size()

int __builtin_ast_type_size ( Type *  ty)

Return sizeof(ty) in bytes.

Parameters
tyThe type to inspect.
Returns
The size in bytes.

Convenience wrapper: TypeSize(ty).

◆ __builtin_ast_unary()

Node * __builtin_ast_unary ( NodeKind  op,
Node *  operand 
)

Build a unary operation AST node.

Parameters
opThe operator kind (NK_NEG, NK_DEREF, ...).
operandThe operand expression.
Returns
The unary expression node.

Convenience wrapper: MakeUnary(op, operand).

◆ __builtin_ast_var_ref()

Node * __builtin_ast_var_ref ( const char *  name)

Build a variable reference AST node.

Parameters
nameThe variable name.
Returns
An NK_VAR node referencing name.

Convenience wrapper: MakeVarRef(name).

◆ __builtin_ast_vararg_at()

Node * __builtin_ast_vararg_at ( int  index)

Return an inline macro's variadic AST argument by zero-based index.

Parameters
indexZero-based variadic argument index.
Returns
The argument node.

Emits a compile-time error if index is out of range or the active macro call is a global-generation string macro.

◆ __builtin_ast_vararg_count()

int __builtin_ast_vararg_count ( void  )

Return the number of variadic arguments for the active macro call.

Returns
Number of arguments after the fixed parameters.

◆ __builtin_ast_vararg_str_at()

const char * __builtin_ast_vararg_str_at ( int  index)

Return a global-generation macro's stringified variadic argument.

Parameters
indexZero-based variadic argument index.
Returns
The stringified token argument.

Emits a compile-time error if index is out of range or the active macro call is an inline AST macro.

◆ __builtin_ast_varargs_as_array()

Node ** __builtin_ast_varargs_as_array ( void  )

Return an inline macro's variadic AST arguments as an array.

Returns
Borrowed array of variadic argument nodes, or NULL when the active inline macro call has no variadic arguments.

The returned array is read-only and valid only for the current macro call's lifetime. It shares nodes with the original macro arguments and does not consume or clone them. Emits a compile-time error if the active macro call is a global-generation string macro.

◆ __builtin_ast_while()

Node * __builtin_ast_while ( Node *  cond,
Node *  body 
)

Create a while loop node.

Parameters
condThe loop condition expression.
bodyThe loop body statement, or NULL to attach one later with LoopSetBody (typically inside a WithLoop(loop) block).
Returns
A NK_FOR node (CCCC represents while as for with no init/inc), or NULL on error.

Convenience wrapper: MakeWhile(cond, body). Assigns the loop's own break/continue targets, so a body statement built with break/continue resolves against this loop – see QuoteLazy (a lazily-parsed body materialises inside this loop's context automatically) and WithLoop/LoopSetBody (an eagerly-parsed Quote() body needs the loop pushed first, since a body argument is evaluated before this call runs).

◆ __builtin_attr_target_kind()

int __builtin_attr_target_kind ( AttrTarget *  target)

Return the kind of declaration decorated by a custom attribute.

◆ __builtin_attr_target_member()

Member * __builtin_attr_target_member ( AttrTarget *  target)

Return the attributed member of an ATTR_TARGET_MEMBER target, else NULL.

◆ __builtin_attr_target_name()

const char * __builtin_attr_target_name ( AttrTarget *  target)

Return the decorated declaration's source name, when available.

◆ __builtin_attr_target_obj()

Obj * __builtin_attr_target_obj ( AttrTarget *  target)

Return the decorated function or global object, or NULL for type targets.

◆ __builtin_attr_target_owner()

Type * __builtin_attr_target_owner ( AttrTarget *  target)

Return the struct or union declaring an ATTR_TARGET_MEMBER target's member, or the function type of an ATTR_TARGET_PARAM target, else NULL.

◆ __builtin_attr_target_param()

Type * __builtin_attr_target_param ( AttrTarget *  target)

Return the attributed parameter's type of an ATTR_TARGET_PARAM target, else NULL.

◆ __builtin_attr_target_param_index()

int __builtin_attr_target_param_index ( AttrTarget *  target)

Return the position of an ATTR_TARGET_PARAM target in its parameter list, else -1.

◆ __builtin_attr_target_token()

Token * __builtin_attr_target_token ( AttrTarget *  target)

Return a source token for the decorated declaration.

◆ __builtin_attr_target_type()

Type * __builtin_attr_target_type ( AttrTarget *  target)

Return the decorated declaration's type.

◆ __builtin_dump_ast_gen()

void __builtin_dump_ast_gen ( Node *  node)

Print __builtin_ast_*() builder calls that would reconstruct the node.

Parameters
nodeThe root node to emit builder calls for.

Covers all node kinds for which relfection.c has a builder. Unsupported kinds are emitted as C comments. Convenience wrapper: DumpAstGen(node).

◆ __builtin_dump_ast_gen_to_string()

const char * __builtin_dump_ast_gen_to_string ( Node *  node)

Render the __builtin_ast_*() builder call sequence to a string.

Parameters
nodeThe root node.
Returns
An arena-allocated NUL-terminated string, or NULL on error.

Convenience wrapper: DumpAstGenToString(node).

◆ __builtin_dump_tree()

void __builtin_dump_tree ( Node *  node)

Print a human-readable tree representation of a node to stdout.

Parameters
nodeThe root node to print.

Reuses the compiler's internal cc_dump_ast text renderer. Convenience wrapper: DumpTree(node).

◆ __builtin_dump_tree_to_string()

const char * __builtin_dump_tree_to_string ( Node *  node)

Render the tree representation to a heap-allocated string.

Parameters
nodeThe root node.
Returns
An arena-allocated NUL-terminated string, or NULL on error.

Convenience wrapper: DumpTreeToString(node).

◆ __builtin_emit_directive()

void __builtin_emit_directive ( const char *  line)

Emit one raw preprocessor directive line into generated output.

Parameters
lineComplete directive text, for example "#ifdef _WIN32".

Convenience wrapper: EmitDirective(line).

◆ __builtin_generate_filter()

void __builtin_generate_filter ( Type *  elem_ty)

Publish void filter_T(T *arr, size_t n, T *out, size_t *out_n, bool (*pred)(T)), writing elements matching pred into out and setting *out_n to the match count.

Convenience wrapper: GenerateFilter(elem_type).

◆ __builtin_generate_map()

void __builtin_generate_map ( Type *  elem_ty)

Publish void map_T(T *arr, size_t n, T *out, T (*f)(T)), writing f(arr[i]) into out[i] for each element.

Convenience wrapper: GenerateMap(elem_type).

◆ __builtin_generate_reduce()

void __builtin_generate_reduce ( Type *  elem_ty)

Publish T reduce_T(T *arr, size_t n, T init, T (*f)(T, T)), folding f over the array starting from init.

Convenience wrapper: GenerateReduce(elem_type).

◆ __builtin_generate_sum()

void __builtin_generate_sum ( Type *  elem_ty)

Publish T sum_T(T *arr, size_t n) summing all elements.

Convenience wrapper: GenerateSum(elem_type).

◆ __builtin_gensym()

const char * __builtin_gensym ( const char *  prefix)

Generate a unique identifier string for macro-created symbols.

Parameters
prefixPrefix for the generated name.
Returns
An arena-allocated string of the form "<prefix>__<n>".

Convenience wrapper: Gensym(prefix).

◆ __builtin_get_comptime_float()

double __builtin_get_comptime_float ( const char *  name)

Read a float/double-typed #pragma comptime variable's value at compile time.

Parameters
nameThe comptime variable's name.
Returns
The double value, or 0.0 if the variable is not defined.

Convenience wrapper: GetComptimeFloat(name).

◆ __builtin_get_comptime_int()

int64_t __builtin_get_comptime_int ( const char *  name)

Read an integer-typed #pragma comptime variable's value at compile time.

Parameters
nameThe comptime variable's name.
Returns
The 64-bit integer value, or 0 if the variable is not defined.

Convenience wrapper: GetComptimeInt(name).

◆ __builtin_get_comptime_member()

Node * __builtin_get_comptime_member ( const char *  var_name,
const char *  field 
)

Read a named field from a comptime struct variable as an AST literal node.

Parameters
var_nameThe comptime struct variable's name.
fieldThe field name to look up.
Returns
A NK_NUM node for the field's value, or NULL on error.

Convenience wrapper: GetComptimeMember(var_name, field).

◆ __builtin_get_comptime_ptr()

Node * __builtin_get_comptime_ptr ( const char *  name)

Return the address of a comptime variable as a generated-code AST pointer node.

Parameters
nameThe comptime variable's name.
Returns
An NK_ADDR node pointing at a static shadow copy of the evaluated comptime variable, or NULL on error.

Convenience wrapper: GetComptimePtr(name).

◆ __builtin_get_comptime_var()

Node * __builtin_get_comptime_var ( const char *  name)

Read a comptime scalar variable as an AST literal node.

Parameters
nameThe comptime variable's name.
Returns
A NK_NUM node representing the variable's value, or NULL on error.

Convenience wrapper: GetComptimeVar(name).

◆ __builtin_get_constexpr_value()

Node * __builtin_get_constexpr_value ( const char *  name)

Read the evaluated initializer of a global constexpr variable as an AST literal node.

Parameters
nameThe constexpr variable's name.
Returns
A NK_NUM node (integer or float, depending on the variable's type), or NULL on error.

Errors at compile time if name does not refer to a visible constexpr variable. Convenience wrapper: GetConstexprValue(name).

◆ __builtin_macro_error_at()

void __builtin_macro_error_at ( Node *  node,
const char *  fmt,
  ... 
)

Emit a compiler error pointing at the source location of a node.

Parameters
nodeA node whose tok field provides file/line/col. May be NULL (falls back to a location-less error).
fmtprintf-style format string, followed by format arguments.

Behaves like the compiler's error_tok(): in normal mode it prints the error with file/line/col and source snippet then aborts via longjmp or exit. When vm->collect_errors is set it records the error and compilation may continue. Convenience wrapper: MacroErrorAt(node, ...).

◆ __builtin_macro_warning_at()

void void __builtin_macro_warning_at ( Node *  node,
const char *  fmt,
  ... 
)

Emit a compiler warning pointing at the source location of a node.

Parameters
nodeA node whose tok field provides file/line/col. May be NULL.
fmtprintf-style format string, followed by format arguments.

Emitted only when -Wcccc-macro is enabled. Non-fatal unless promoted with -Werror or -Werror=cccc-macro. Convenience wrapper: MacroWarningAt(node, ...).

◆ __builtin_macroexpand()

Node * __builtin_macroexpand ( Node *  node)

Lisp-style full macro expansion.

Repeatedly calls __builtin_macroexpand_1 on the top-level node until it is no longer an NK_MACRO_CALL (i.e. the form is stable). Does not recurse into child nodes. Respects the VM's macro_recursion_limit. Convenience wrapper: MacroExpand(node).

Parameters
nodeThe node to fully expand.
Returns
The fully expanded node, or node itself if it is not a macro call.

◆ __builtin_macroexpand_1()

Node * __builtin_macroexpand_1 ( Node *  node)

Lisp-style single-step macro expansion (macroexpand-1 semantics).

If node is an NK_MACRO_CALL node, execute the macro once and return the resulting node without splicing it into the AST or recursing into nested macro calls. If node is not a macro call, it is returned unchanged (identity). Convenience wrapper: MacroExpand1(node).

Parameters
nodeThe node to (possibly) expand.
Returns
The expanded node, or node itself if it is not a macro call.

◆ __builtin_node_list()

Node * __builtin_node_list ( Node **  nodes,
int  count 
)

Build a ->next-linked node chain from an array, returning the head. Use the result as the argument to a $@k list splice.

Parameters
nodesArray of Node* to link together. Linking stops at the first NULL element or at count, whichever comes first.
countNumber of elements in the array.
Returns
Head of the chain, or NULL if count == 0 or nodes is NULL.

A single node is a valid chain of length 1. An existing ->next chain (e.g. __builtin_ast_block(...)->body) can also be passed directly as the splice argument without going through this helper. Convenience wrapper: NodeList(nodes, count).

◆ __builtin_quote()

void void Node * __builtin_quote ( const char *  tmpl,
  ... 
)

Parse a C code template string into an AST node, substituting splice points with the provided argument nodes.

Parameters
tmplA C expression or statement as a string literal.

Scalar splices — replace a single position with one node:

  • $1, $2, ... positional (1-indexed, reorderable, reusable).
  • $$ sequential (left-to-right); cannot be mixed with $N.

List splices — expand a statement-position placeholder into a chain of N statements (ticket #172):

  • $@1, $@2, ... positional list splice. The argument must be a ->next-linked node chain (see NodeList / __builtin_node_list). Each $@k; in the template is replaced by the entire chain.
  • $@ sequential list splice, parallel to $$.
  • List splice identifiers ($@k) may share their index with scalar splices ($k) in the same template, but positional and incremental styles cannot be mixed within one template.

List splices are valid in statement-list position (inside a { ... } block), direct call-argument position, or compound-literal initializer lists. Using $@k as an expression operand is a compile-time error.

Parameters
...Node* arguments corresponding to the splice points.
Returns
The parsed and substituted AST node, or NULL on error.

Template is parsed and substituted at macro-execution (compile) time; there is no runtime overhead. Expressions and statements are auto-detected. The variadic form supports up to 64 splice nodes; use __builtin_quote_n for larger node arrays. Convenience wrapper: Quote(tmpl, ...).

◆ __builtin_quote_lazy()

Node * __builtin_quote_lazy ( const char *  tmpl,
  ... 
)

Deferred (unparsed) quasi-quote: captures a template and its splice arguments without parsing it.

Parameters
tmplA C expression or statement as a string literal with $N / $@N splice points, exactly as for Quote(). Copied, not parsed, here.
...Node* arguments corresponding to the splice points.
Returns
An opaque ND_QUOTE_LAZY node. It is not a usable AST fragment by itself – it must be spliced into another Quote()/QuoteLazy() template (as a $N argument, in either statement or expression position) or passed to FunctionSetBody. At that splice site the template is tokenized and parsed for the first time, inside the splice site's own scope and loop context – so the fragment can reference a variable that is only in scope there, and a break/ continue inside it binds to a for/while/switch built by a separate, outer Quote()/QuoteLazy() call.

Not valid as a $@N list-splice argument – list splices require already-parsed nodes; use Quote()/QuoteN() for those. Splicing the same QuoteLazy() result more than once re-parses it at each site, producing an independent fragment each time (any locals it declares are not shared – use Gensym if that matters). The variadic form supports up to 64 splice nodes; use QuoteLazyN for larger node arrays. Convenience wrapper: QuoteLazy(tmpl, ...).

◆ __builtin_quote_lazy_n()

Node * __builtin_quote_lazy_n ( const char *  tmpl,
Node **  nodes,
int  count 
)

Array-form deferred quasi-quote; see __builtin_quote_lazy.

Parameters
tmplTemplate string with $N / $@N splice points.
nodesArray of Node* splice arguments.
countLength of the nodes array. If any $K in the template exceeds count, a compile-time error is emitted at this call.
Returns
An opaque ND_QUOTE_LAZY node; see __builtin_quote_lazy.

Convenience wrapper: QuoteLazyN(tmpl, nodes, count).

◆ __builtin_quote_n()

Node * __builtin_quote_n ( const char *  tmpl,
Node **  nodes,
int  count 
)

Array-form quasi-quote that validates the caller-provided splice count and supports larger node arrays than the variadic form.

Parameters
tmplA C expression or statement as a string literal with $N / $@N splice points.
nodesArray of Node* splice arguments.
countLength of the nodes array. If any $K in the template exceeds count, a compile-time error is emitted.
Returns
The parsed and substituted AST node, or NULL on error.

Convenience wrapper: QuoteN(tmpl, nodes, count).

◆ __CCCC_TAG() [1/8]

struct __CCCC_TAG ( AttrTarget  )

Opaque handle to the declaration a custom @attribute handler was invoked on. Inspected with the AttrTarget* family of macros inside a function registered via @comptime(attribute("...")).

◆ __CCCC_TAG() [2/8]

struct __CCCC_TAG ( EnumConstant  )

Opaque enum constant descriptor, returned by EnumAt / EnumFind and inspected with EnumConstantName / EnumConstantValue.

◆ __CCCC_TAG() [3/8]

struct __CCCC_TAG ( Member  )

Opaque struct/union member descriptor, returned by StructMemberAt / StructMemberFind and inspected with the Member* family of macros.

◆ __CCCC_TAG() [4/8]

struct __CCCC_TAG ( Node  )

Opaque AST node (expression, statement, or literal). Built with the Make* family of macros and spliced into the compiled program by returning it from a comptime function or via PublishNode.

◆ __CCCC_TAG() [5/8]

struct __CCCC_TAG ( Obj  )

Opaque global symbol (a function or global variable). Created by MakeFunction / GlobalVar, or looked up with FindGlobal / GlobalAt.

◆ __CCCC_TAG() [6/8]

struct __CCCC_TAG ( Token  )

Opaque source-location handle attached to AST nodes for diagnostics. Obtained via CurrentToken / SyntheticToken / TokenFromNode and attached with SetToken.

◆ __CCCC_TAG() [7/8]

struct __CCCC_TAG ( Type  )

Opaque compiler type descriptor (primitive, pointer, array, function, struct/union, or enum). Inspect it with the GetTypeKind / Type* family of macros.

◆ __CCCC_TAG() [8/8]

struct __CCCC_TAG ( VirtualMachine  )

Opaque compiler/VM instance. Macro authors never see or pass this; functions that need it read it internally from a process-global set for the duration of macro execution.