|
CCCC
C bytecode compiler + VM interpreter
|
Reflection and AST Construction API for CCCC Comptime Functions. More...
#include <stdbool.h>#include <stddef.h>#include <stdint.h>#include <string.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. | |
Reflection and AST Construction API for CCCC Comptime Functions.
This header provides APIs for:
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.
int x = my_macro();): the function must return a non-NULL node. Returning NULL is an error.my_macro(); at file scope): there is no expression to replace. Returning NULL — or declaring the function void — is legal and means "I only emitted definitions."Declare a definition-only function with a void return type for clarity:
A void comptime function used in expression position is a compile error.
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.
| #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 __builtin_dispatch_2 | ( | _1, | |
| _2, | |||
| which, | |||
| ... | |||
| ) | which(_1, _2) |
| #define __builtin_dispatch_3 | ( | _1, | |
| _2, | |||
| _3, | |||
| which, | |||
| ... | |||
| ) | which(_1, _2, _3) |
| #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 __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 __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 __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 __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 __CCCC_TAG | ( | n | ) | __cccc_##n |
| #define AddAttribute | ( | fn, | |
| text | |||
| ) | __builtin_ast_add_attribute(fn, text) |
Apply an attribute string to a programmatically created function.
| fn | The function object to attribute (created by MakeFunction). |
| text | Attribute text as it would appear between [[ and ]], e.g. "cccc::test", "nodiscard", or "@myattr". |
| #define AsmClobberAt | ( | node, | |
| i | |||
| ) | __builtin_ast_asm_clobber_at(node, i) |
Return a clobber of an NK_ASM statement.
| node | An NK_ASM node. |
| i | Zero-based clobber index. |
| #define AsmClobberCount | ( | node | ) | __builtin_ast_asm_clobber_count(node) |
Return the number of clobbers of an NK_ASM statement.
| node | An NK_ASM node. |
| #define AsmGotoLabelAt | ( | node, | |
| i | |||
| ) | __builtin_ast_asm_goto_label_at(node, i) |
Return a jump label name of an asm goto.
| node | An NK_ASM node. |
| i | Zero-based label index. |
| #define AsmGotoLabelCount | ( | node | ) | __builtin_ast_asm_goto_label_count(node) |
Return the number of jump labels of an asm goto.
| node | An NK_ASM node. |
| #define AsmInputCount | ( | node | ) | __builtin_ast_asm_input_count(node) |
Return the number of input operands of an NK_ASM statement.
| node | An NK_ASM node. |
| #define AsmIsGoto | ( | node | ) | __builtin_ast_asm_is_goto(node) |
Return whether an NK_ASM statement is an asm goto.
| node | An NK_ASM node. |
| #define AsmIsVolatile | ( | node | ) | __builtin_ast_asm_is_volatile(node) |
Return whether an NK_ASM statement is written volatile.
| node | An NK_ASM node. |
| #define AsmOperandConstraint | ( | node, | |
| i | |||
| ) | __builtin_ast_asm_operand_constraint(node, i) |
Return the constraint string of an asm operand.
| node | An NK_ASM node. |
| i | Zero-based operand index; outputs come before inputs. |
| #define AsmOperandExpr | ( | node, | |
| i | |||
| ) | __builtin_ast_asm_operand_expr(node, i) |
Return the expression of an asm operand.
| node | An NK_ASM node. |
| i | Zero-based operand index; outputs come before inputs. |
| #define AsmOperandName | ( | node, | |
| i | |||
| ) | __builtin_ast_asm_operand_name(node, i) |
Return the symbolic name of an asm operand, or NULL.
| node | An NK_ASM node. |
| i | Zero-based operand index; outputs come before inputs. |
| #define AsmOutputCount | ( | node | ) | __builtin_ast_asm_output_count(node) |
Return the number of output operands of an NK_ASM statement.
| node | An NK_ASM node. |
| #define AsmTemplate | ( | node | ) | __builtin_ast_asm_template(node) |
Return the template string of an NK_ASM statement.
| node | An NK_ASM node. |
| #define AtomicFailOrder | ( | node | ) | __builtin_ast_atomic_fail_order(node) |
Return the failure memory order of an NK_CAS, -1 for other kinds.
| node | An NK_CAS node. |
| #define AtomicIsWeak | ( | node | ) | __builtin_ast_atomic_is_weak(node) |
Return whether an NK_CAS was written as a weak compare-exchange.
| node | An NK_CAS node. |
| #define AtomicOrder | ( | node | ) | __builtin_ast_atomic_order(node) |
Return the __ATOMIC_* memory order of an atomic node, -1 for other kinds.
| node | An NK_CAS, NK_EXCH, NK_ALOAD or NK_ASTORE node. |
| #define AttrTargetMember | ( | target | ) | __builtin_attr_target_member(target) |
Return the attributed member of an ATTR_TARGET_MEMBER target.
| target | The attribute target to inspect. |
| #define AttrTargetName | ( | target | ) | __builtin_attr_target_name(target) |
Return the decorated declaration's source name, when available.
| target | The attribute target to inspect. |
| #define AttrTargetObj | ( | target | ) | __builtin_attr_target_obj(target) |
Return the decorated function or global object, or NULL for type targets.
| target | The attribute target to inspect. |
| #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.
| target | The attribute target to inspect. |
| #define AttrTargetParam | ( | target | ) | __builtin_attr_target_param(target) |
Return the attributed parameter's type of an ATTR_TARGET_PARAM target.
| target | The attribute target to inspect. |
| #define AttrTargetParamIndex | ( | target | ) | __builtin_attr_target_param_index(target) |
Return the position of an ATTR_TARGET_PARAM target in its parameter list, or -1.
| target | The attribute target to inspect. |
| #define AttrTargetToken | ( | target | ) | __builtin_attr_target_token(target) |
Return a source token for the decorated declaration.
| target | The attribute target to inspect. |
| #define AttrTargetType | ( | target | ) | __builtin_attr_target_type(target) |
Return the decorated declaration's type.
| target | The attribute target to inspect. |
| #define BitopOp | ( | node | ) | __builtin_ast_bitop_op(node) |
Return the operation (AST_BITOP_*) of an NK_BITOP.
| node | An NK_BITOP node. |
| #define BitopWidth | ( | node | ) | __builtin_ast_bitop_width(node) |
Return the bit width of an NK_BITOP's builtin.
| node | An NK_BITOP node. |
| #define BlockAddStmt | ( | ... | ) |
Append a statement to a block.
| ... | Either (stmt) inside a WithBlock(block) block, or (block, stmt) to name the block explicitly. |
Dispatches on argument count via __builtin_dispatch_2.
| #define BlockAt | ( | block, | |
| i | |||
| ) | __builtin_ast_block_at(block, i) |
Return a statement of an NK_BLOCK or NK_STMT_EXPR.
| block | The block node. |
| i | Zero-based statement index. |
| #define BlockCount | ( | block | ) | __builtin_ast_block_count(block) |
Return the number of statements in an NK_BLOCK or NK_STMT_EXPR.
| block | The block node. |
| #define CallArgAt | ( | call, | |
| i | |||
| ) | __builtin_ast_call_arg_at(call, i) |
Return an argument of a call.
| call | An NK_FUNCALL node (or the comma wrapper around one). |
| i | Zero-based argument index. |
| #define CallArgCount | ( | call | ) | __builtin_ast_call_arg_count(call) |
Return the number of arguments of a call.
| call | An NK_FUNCALL node (or the comma wrapper around one). |
| #define CallCallee | ( | call | ) | __builtin_ast_call_callee(call) |
Return the callee expression of a call.
| call | An NK_FUNCALL node (or the comma wrapper around one). |
| #define CasAddr | ( | node | ) | __builtin_ast_cas_addr(node) |
Return the address operand of an NK_CAS.
| node | An NK_CAS node. |
| #define CasDesired | ( | node | ) | __builtin_ast_cas_desired(node) |
Return the desired-value operand of an NK_CAS.
| node | An NK_CAS node. |
| #define CaseBegin | ( | node | ) | __builtin_ast_case_begin(node) |
Return the first value of an NK_CASE label.
| node | An NK_CASE node. |
| #define CaseBody | ( | node | ) | __builtin_ast_case_body(node) |
Return the statement that follows an NK_CASE label.
| node | An NK_CASE node. |
| #define CaseEnd | ( | node | ) | __builtin_ast_case_end(node) |
Return the last value of an NK_CASE label (equal to CaseBegin unless a GNU range).
| node | An NK_CASE node. |
| #define CasExpected | ( | node | ) | __builtin_ast_cas_expected(node) |
Return the expected-value operand of an NK_CAS.
| node | An NK_CAS node. |
| #define CompoundLiteral | ( | ty, | |
| ... | |||
| ) |
Build a positional compound literal; element count is inferred from the argument list.
Positional compound literal — element count inferred from VA_ARGS.
| ty | The compound literal's type. |
| ... | Node* initializer values, assigned positionally. |
Requires function scope (file-scope is not supported).
| #define ConstIntValue | ( | node, | |
| out | |||
| ) | __builtin_ast_const_int_value(node, out) |
Evaluate an integer constant expression node; false if it is not one.
| node | A node, typically a macro or attribute argument. |
| out | An int64_t * that receives the value. |
| #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.
| node | A node, typically a macro or attribute argument. |
| out | A uint64_t * that receives the value. |
| #define CopyLocation | ( | dst, | |
| src | |||
| ) | __builtin_ast_copy_location(dst, src) |
Copy the source token from src to dst.
| dst | Generated node to update. |
| src | Source node whose location should be reused. |
| #define CopyNode | ( | n | ) | __builtin_ast_copy_node(n) |
Deep-copy an expression or simple statement so it can be linked into a second list.
| n | Node to copy. |
| #define CurrentToken | ( | ) | __builtin_ast_current_token() |
Return the token for the macro invocation currently being executed.
| #define Deserialize | ( | ty, | |
| buf | |||
| ) | __builtin_ast_deserialize(ty, buf) |
Build an expression that reconstructs a ty value from buf.
| ty | The type to reconstruct. |
| buf | The source buffer, laid out as Serialize writes it. |
Padding in the result is zero and buf needs no particular alignment.
| #define DumpAstGen | ( | node | ) | __builtin_dump_ast_gen(node) |
Print __builtin_ast_*() builder calls that would reconstruct node.
| node | The root node to emit builder calls for. |
| #define DumpAstGenToString | ( | node | ) | __builtin_dump_ast_gen_to_string(node) |
Render the __builtin_ast_*() builder call sequence for node to a string.
| node | The root node. |
| #define DumpTree | ( | node | ) | __builtin_dump_tree(node) |
Print a human-readable tree representation of node to stdout.
| node | The root node to print. |
| #define DumpTreeToString | ( | node | ) | __builtin_dump_tree_to_string(node) |
Render the tree representation of node to a heap-allocated string.
| node | The root node. |
| #define EmitDirective | ( | line | ) | __builtin_emit_directive(line) |
Emit one raw preprocessor directive line into generated output.
| line | Complete directive text, for example "#ifdef _WIN32". |
| #define EnumAddConstant | ( | ... | ) |
Add a named constant to an enum type and expose it in scope.
| ... | 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.
| #define EnumAt | ( | ty, | |
| i | |||
| ) | __builtin_ast_enum_at(ty, i) |
Return the enum constant at a given index.
| ty | The enum type to inspect. |
| i | Zero-based index. |
| #define EnumConstantName | ( | ec | ) | __builtin_ast_enum_constant_name(ec) |
Return the name of an enum constant.
| ec | The enum constant. |
| #define EnumConstantValue | ( | ec | ) | __builtin_ast_enum_constant_value(ec) |
Return the integer value of an enum constant.
| ec | The enum constant. |
| #define EnumCount | ( | ty | ) | __builtin_ast_enum_count(ty) |
Return the number of constants in an enum type.
| ty | The enum type to inspect. |
| #define EnumFind | ( | ty, | |
| name | |||
| ) | __builtin_ast_enum_find(ty, name) |
Look up an enum constant by name.
| ty | The enum type to search. |
| name | The constant name to look up. |
| #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.
| ty | The enum type. |
| expr | The expression to compare (a const char *). |
Wrap the result in a function returning the enum type (or an int).
| #define EnumName | ( | ty | ) | __builtin_ast_enum_name(ty) |
Return the tag name of an enum type.
| ty | The enum type to inspect. |
| #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.
| ty | The enum type. |
| expr | The expression to switch on (the enum value). |
Wrap the result in a function returning const char *.
| #define EnumValue | ( | ty, | |
| i | |||
| ) | __builtin_ast_enum_value(ty, i) |
Return the integer value of the enum constant at the given index.
| ty | The enum type to inspect. |
| i | Zero-based index. |
| #define EnumValueCount | ( | ty | ) | __builtin_ast_enum_value_count(ty) |
Return the number of values in an enum type.
| ty | The enum type to inspect. |
| #define EnumValueName | ( | ty, | |
| i | |||
| ) | __builtin_ast_enum_value_name(ty, i) |
Return the name of the enum constant at the given index.
| ty | The enum type to inspect. |
| i | Zero-based index. |
| #define FenceIsSignal | ( | node | ) | __builtin_ast_fence_is_signal(node) |
Return whether an NK_FENCE is a signal fence.
| node | An NK_FENCE node. |
| #define FindGlobal | ( | name | ) | __builtin_ast_find_global(name) |
Look up a global symbol by name.
| name | The global name to look up. |
| #define FindType | ( | name | ) | __builtin_ast_find_type(name) |
Look up a type by tag name (struct/union/enum).
| name | The tag name to look up. |
| #define FnBody | ( | fn | ) | __builtin_ast_function_body(fn) |
Return the top-level block of a function definition.
| fn | A function Obj. |
| #define FnLocalAt | ( | fn, | |
| i | |||
| ) | __builtin_ast_function_local_at(fn, i) |
Return a local variable of a function definition, in declaration order.
| fn | A function Obj. |
| i | Zero-based local index. |
| #define FnLocalCount | ( | fn | ) | __builtin_ast_function_local_count(fn) |
Return the number of source-level locals of a function definition.
| fn | A function Obj. |
| #define FnParamAt | ( | fn, | |
| i | |||
| ) | __builtin_ast_function_param_at(fn, i) |
Return a parameter of a function definition, in declaration order.
| fn | A function Obj. |
| i | Zero-based parameter index. |
| #define FnParamCount | ( | fn | ) | __builtin_ast_function_param_count(fn) |
Return the number of parameters of a function definition.
| fn | A function Obj. |
| #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.
| type | The struct/union Type* to iterate. |
| varname | Identifier bound to each Member* in turn. |
| body | Compound 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.
| #define FunctionAddParam | ( | fn, | |
| name, | |||
| type | |||
| ) | __builtin_ast_function_add_param(fn, name, type) |
Add a parameter to a function.
| fn | The function object. |
| name | The parameter name. |
| type | The parameter type. |
Call once per parameter, in order.
| #define FunctionPrototype | ( | name, | |
| ret | |||
| ) | __builtin_ast_function_prototype(name, ret) |
Create a function forward declaration (prototype) without a body.
| name | The function name. |
| ret | The 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.
| #define FunctionSetBody | ( | fn, | |
| body | |||
| ) | __builtin_ast_function_set_body(fn, body) |
Set the body of a function.
| fn | The function object. |
| body | The 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.
| #define FunctionSetInline | ( | fn, | |
| is_inline | |||
| ) | __builtin_ast_function_set_inline(fn, is_inline) |
Set whether a function is inline.
| fn | The function object. |
| is_inline | True for inline, false otherwise. |
| #define FunctionSetStatic | ( | fn, | |
| is_static | |||
| ) | __builtin_ast_function_set_static(fn, is_static) |
Set whether a function has static linkage.
| fn | The function object. |
| is_static | True for static linkage, false for external. |
| #define FunctionSetVariadic | ( | fn, | |
| is_variadic | |||
| ) | __builtin_ast_function_set_variadic(fn, is_variadic) |
Set whether a function is variadic.
| fn | The function object. |
| is_variadic | True for variadic, false otherwise. |
| #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)).
| elem_type | The element type T. |
| #define GenerateMap | ( | elem_type | ) | __builtin_generate_map(elem_type) |
Publish void map_T(T *arr, size_t n, T *out, T (*f)(T)).
| elem_type | The element type 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)).
| elem_type | The element type T. |
| #define GenerateSum | ( | elem_type | ) | __builtin_generate_sum(elem_type) |
Publish T sum_T(T *arr, size_t n) summing all elements.
| elem_type | The element type T. |
| #define Gensym | ( | prefix | ) | __builtin_gensym(prefix) |
Generate a unique identifier string for macro-created symbols.
| prefix | Prefix for the generated name. |
| #define GetAttrTargetKind | ( | target | ) | __builtin_attr_target_kind(target) |
Return the kind of declaration decorated by a custom attribute.
| target | The attribute target to inspect. |
| #define GetComptimeFloat | ( | name | ) | __builtin_get_comptime_float(name) |
Read a float/double-typed #pragma comptime variable's value at compile time.
| name | The comptime variable's name. |
| #define GetComptimeInt | ( | name | ) | __builtin_get_comptime_int(name) |
Read an integer-typed #pragma comptime variable's value at compile time.
| name | The comptime variable's name. |
| #define GetComptimeMember | ( | var, | |
| field | |||
| ) | __builtin_get_comptime_member(var, field) |
Read a named field from a comptime struct variable as an AST literal node.
| var | The comptime struct variable's name. |
| field | The field name to look up. |
| #define GetComptimePtr | ( | name | ) | __builtin_get_comptime_ptr(name) |
Return the address of a comptime variable as a generated-code AST pointer node.
| name | The comptime variable's name. |
| #define GetComptimeVar | ( | name | ) | __builtin_get_comptime_var(name) |
Read a comptime scalar variable as an AST literal node.
| name | The comptime variable's name. |
| #define GetConstexprValue | ( | name | ) | __builtin_get_constexpr_value(name) |
Read the evaluated initializer of a global constexpr variable as an AST literal node.
| name | The constexpr variable's name. |
Errors at compile time if name does not refer to a visible constexpr variable.
| #define GetNodeKind | ( | node | ) | __builtin_ast_node_kind(node) |
Return the kind of a node.
| node | The node to inspect. |
| #define GetNodeType | ( | node | ) | __builtin_ast_node_type(node) |
Return the resolved type of an expression node.
| node | The node to inspect. |
| #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.
| name | The type name to look up. |
| #define GetTypeKind | ( | ty | ) | __builtin_ast_type_kind(ty) |
Return the TypeKind tag of a type.
| ty | The type to inspect. |
| #define GlobalAt | ( | i | ) | __builtin_ast_global_at(i) |
Return the global symbol at the given index.
| i | Zero-based global index. |
| #define GlobalCount | ( | ) | __builtin_ast_global_count() |
Return the total number of global symbols.
| #define GlobalVar | ( | name, | |
| ty | |||
| ) | __builtin_ast_global_var(name, ty) |
Create a new named global variable definition.
| name | The variable name (must be unique among globals). |
| ty | The variable type. |
| #define GlobalVarSetInitData | ( | var, | |
| data, | |||
| len | |||
| ) | __builtin_ast_global_var_set_init_data(var, data, len) |
Set the initial data for a generated global variable.
| var | The global variable object. |
| data | Pointer to the raw byte data. |
| len | Number of bytes to copy (must equal var's type size). |
| #define GlobalVarSetStatic | ( | var, | |
| is_static | |||
| ) | __builtin_ast_global_var_set_static(var, is_static) |
Set the static (internal linkage) flag on a generated global.
| var | The global variable object. |
| is_static | True for internal (file-scope static) linkage. |
| #define GotoJumpKind | ( | node | ) | __builtin_ast_goto_jump_kind(node) |
Return which statement an NK_GOTO came from (AST_JUMP_*).
| node | The node to inspect. |
| #define InitArray | ( | elem_ty, | |
| ... | |||
| ) |
Build an array compound literal with an explicit element type.
Array compound literal with explicit element type.
| elem_ty | The array element type. |
| ... | Node* element values; count is inferred from the argument list. |
| #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.
| ty | The struct/union type. |
| fields | Array of field-name strings. |
| values | Array of Node* values, parallel to fields. |
| n | Number of (field, value) pairs. |
Partial init (n less than the member count) is allowed.
| #define LabelName | ( | node | ) | __builtin_ast_label_name(node) |
Return the name of an NK_GOTO, NK_LABEL or NK_LABEL_VAL.
| node | The node to inspect. |
| #define LoopSetBody | ( | loop, | |
| body | |||
| ) | __builtin_ast_loop_set_body(loop, body) |
Attach body to loop (from MakeWhile/MakeFor/MakeDoWhile).
| loop | The loop node to attach the body to. |
| body | The loop body statement. |
| #define MacroCallArgAt | ( | node, | |
| i | |||
| ) | __builtin_ast_macro_call_arg_at(node, i) |
Return an argument of an NK_MACRO_CALL.
| node | The node to inspect. |
| i | Zero-based argument index. |
| #define MacroCallArgCount | ( | node | ) | __builtin_ast_macro_call_arg_count(node) |
Return the argument count of an NK_MACRO_CALL.
| node | The node to inspect. |
| #define MacroCallName | ( | node | ) | __builtin_ast_macro_call_name(node) |
Return the macro name of a not-yet-expanded NK_MACRO_CALL.
| node | The node to inspect. |
| #define MacroErrorAt | ( | node, | |
| ... | |||
| ) | __builtin_macro_error_at(node, __VA_ARGS__) |
Emit a compiler error pointing at node's source location.
| node | A node whose tok field provides file/line/col, or NULL. |
| ... | printf-style format string, followed by format arguments. |
| #define MacroExpand | ( | node | ) | __builtin_macroexpand(node) |
Lisp-style full macro expansion; repeats MacroExpand1 until the form is stable.
| node | The node to fully expand. |
| #define MacroExpand1 | ( | node | ) | __builtin_macroexpand_1(node) |
Lisp-style single-step macro expansion (macroexpand-1 semantics).
| node | The node to (possibly) expand. |
| #define MacroWarningAt | ( | node, | |
| ... | |||
| ) | __builtin_macro_warning_at(node, __VA_ARGS__) |
Emit a compiler warning pointing at node's source location (only under -Wcccc-macro).
| node | A node whose tok field provides file/line/col, or NULL. |
| ... | printf-style format string, followed by format arguments. |
| #define MakeAlignofType | ( | ty | ) | __builtin_ast_alignof_type(ty) |
Emit _Alignof(ty) as a compile-time integer literal.
| ty | The type to measure. |
| #define MakeArray | ( | base, | |
| len | |||
| ) | __builtin_ast_make_array(base, len) |
Build a fixed-length array type.
| base | The element type. |
| len | The element count. |
| #define MakeAssign | ( | target, | |
| value | |||
| ) | __builtin_ast_assign(target, value) |
Build an assignment node (target = value).
| target | The lvalue expression being assigned to. |
| value | The rvalue expression to assign. |
| #define MakeBinary | ( | op, | |
| l, | |||
| r | |||
| ) | __builtin_ast_binary(op, l, r) |
Build a binary operation AST node.
| op | The operator kind (NK_ADD, NK_SUB, ...). |
| l | The left-hand operand. |
| r | The right-hand operand. |
| #define MakeBlock | ( | stmts, | |
| count | |||
| ) | __builtin_ast_block(stmts, count) |
Build a block (compound statement) node.
| stmts | Array of statement nodes, or NULL if count is 0. |
| count | Number of statements in the array. |
| #define MakeCast | ( | expr, | |
| ty | |||
| ) | __builtin_ast_cast(expr, ty) |
Build a type cast AST node.
| expr | The expression to cast. |
| ty | The type to cast to. |
| #define MakeComma | ( | lhs, | |
| rhs | |||
| ) | __builtin_ast_comma(lhs, rhs) |
Build a comma expression: evaluate lhs, yield rhs.
| lhs | The expression evaluated for side effects. |
| rhs | The expression whose value is the result. |
| #define MakeCond | ( | c, | |
| t, | |||
| e | |||
| ) | __builtin_ast_cond(c, t, e) |
Build a ternary conditional expression node (c ? t : e).
| c | The condition expression. |
| t | The expression evaluated when c is non-zero. |
| e | The expression evaluated when c is zero. |
| #define MakeConst | ( | ty | ) | __builtin_ast_make_const(ty) |
Return a const-qualified copy of ty.
| ty | The type to qualify. |
| #define MakeDoWhile | ( | body, | |
| cond | |||
| ) | __builtin_ast_do_while(body, cond) |
Create a do-while loop node.
| body | The loop body. |
| cond | The loop condition (tested after each iteration). |
| #define MakeEnum | ( | name | ) | __builtin_ast_make_enum(name) |
Create and expose a new named enum type.
| name | The enum tag name. |
Use EnumAddConstant to add constants after creation.
| #define MakeExprStmt | ( | expr | ) | __builtin_ast_expr_stmt(expr) |
Build an expression statement node.
| expr | The expression to evaluate for side effects. |
| #define MakeFloatLiteral | ( | val | ) | __builtin_ast_float_literal(val) |
Build a floating-point literal AST node.
| val | The floating-point value. |
| #define MakeFor | ( | init, | |
| cond, | |||
| inc, | |||
| body | |||
| ) | __builtin_ast_for(init, cond, inc, body) |
Create a for loop node.
| init | Initialiser expression/statement (may be NULL). |
| cond | Loop condition (may be NULL for infinite loop). |
| inc | Increment expression (may be NULL). |
| body | Loop body. |
| #define MakeFuncCall | ( | callee, | |
| args, | |||
| n | |||
| ) | __builtin_ast_funcall(callee, args, n) |
Create a function call node.
| callee | An expression node that evaluates to a function (or function pointer). |
| args | Array of argument nodes (may be NULL if n == 0). |
| n | Number of arguments. |
| #define MakeFuncPtrType | ( | ret, | |
| params, | |||
| n | |||
| ) | __builtin_ast_make_func_ptr_type(ret, params, n) |
Build a pointer-to-function type, e.g. "T (*)(T)".
| ret | The function's return type. |
| params | Array of parameter types. |
| n | Number of entries in params (max 16). |
| #define MakeFunction | ( | name, | |
| ret_type | |||
| ) | __builtin_ast_function(name, ret_type) |
Create a new function object, automatically added to the globals list.
| name | The function name. |
| ret_type | The return type. |
| #define MakeIf | ( | c, | |
| t, | |||
| e | |||
| ) | __builtin_ast_if(c, t, e) |
Build an if statement node.
| c | The condition expression. |
| t | The body executed when c is non-zero. |
| e | The body executed when c is zero, or NULL. |
| #define MakeIntLiteral | ( | val | ) | __builtin_ast_int_literal(val) |
Build an integer literal AST node.
| val | The integer value. |
| #define MakeLocalVar | ( | name, | |
| ty | |||
| ) | __builtin_ast_local_var(name, ty) |
Declare a named local variable in the current function scope.
| name | The variable name (user-visible). |
| ty | The variable type. |
For temporaries that must not capture user names, prefer MakeLocalVarUnique.
| #define MakeLocalVarUnique | ( | ty | ) | __builtin_ast_local_var_unique(ty) |
Declare a hygienic (gensym'd) local variable in the current function scope.
| ty | The variable type. |
The safe default for macro temporaries; the generated name cannot collide with a user identifier.
| #define MakeMember | ( | obj, | |
| name | |||
| ) | __builtin_ast_member(obj, name) |
Create a struct/union member access node (obj.name).
| obj | An expression node whose type must be a struct or union. |
| name | The member name as a NUL-terminated string. |
Dereference pointers first (e.g. via MakeUnary(NK_DEREF, ...)); this does not do it for you.
| #define MakeNull | ( | ) | __builtin_ast_null() |
Build a typed null pointer node: (void *)0.
| #define MakeParamRef | ( | fn, | |
| name | |||
| ) | __builtin_ast_param_ref(fn, name) |
Build a reference to a function parameter by name.
| fn | The function object whose parameter is being referenced. |
| name | The parameter name. |
| #define MakePointer | ( | base | ) | __builtin_ast_make_pointer(base) |
Build a pointer-to-base type.
| base | The pointed-to type. |
| #define MakeReturn | ( | expr | ) | __builtin_ast_return(expr) |
Build a return statement node.
| expr | The value to return (may be NULL for a void return). |
| #define MakeSizeofExpr | ( | expr | ) | __builtin_ast_sizeof_expr(expr) |
Emit sizeof(expr): resolves the expression's type then its size.
| expr | The expression whose type to measure. |
| #define MakeSizeofType | ( | ty | ) | __builtin_ast_sizeof_type(ty) |
Emit sizeof(ty) as a compile-time integer literal.
| ty | The type to measure. |
| #define MakeStringLiteral | ( | str | ) | __builtin_ast_string_literal(str) |
Build a string literal AST node.
| str | A NUL-terminated string. |
| #define MakeStruct | ( | name | ) | __builtin_ast_make_struct(name) |
Create and expose a new named struct type.
| name | The struct tag name. |
Use StructAddField to add fields after creation.
| #define MakeSubscript | ( | arr, | |
| idx | |||
| ) | __builtin_ast_subscript(arr, idx) |
Build an array subscript node: arr[idx], desugared as *(arr+idx).
| arr | The array (or pointer) expression. |
| idx | The index expression. |
| #define MakeSwitch | ( | cond | ) | __builtin_ast_switch(cond) |
Build a switch statement node.
| cond | The expression to switch on. |
Use SwitchAddCase / SwitchSetDefault (or WithSwitch) to populate it.
| #define MakeTypedef | ( | name, | |
| underlying | |||
| ) | __builtin_ast_make_typedef(name, underlying) |
Register a typedef alias for a type and expose it in scope.
| name | The typedef name. |
| underlying | The aliased type. |
| #define MakeUnary | ( | op, | |
| operand | |||
| ) | __builtin_ast_unary(op, operand) |
Build a unary operation AST node.
| op | The operator kind (NK_NEG, NK_DEREF, ...). |
| operand | The operand expression. |
| #define MakeUnion | ( | name | ) | __builtin_ast_make_union(name) |
Create and expose a new named union type.
| name | The union tag name. |
| #define MakeVarRef | ( | name | ) | __builtin_ast_var_ref(name) |
Build a variable reference AST node.
| name | The variable name. |
| #define MakeVolatile | ( | ty | ) | __builtin_ast_make_volatile(ty) |
Return a volatile-qualified copy of ty.
| ty | The type to qualify. |
| #define MakeWhile | ( | cond, | |
| body | |||
| ) | __builtin_ast_while(cond, body) |
Create a while loop node.
| cond | The loop condition expression. |
| body | The loop body statement. |
| #define MarkAsBuild | ( | fn | ) | AddAttribute(fn, "cccc::build") |
Shorthand for AddAttribute(fn, "cccc::build").
| fn | The function object. |
| #define MarkAsBuildTarget | ( | fn, | |
| kind | |||
| ) | __builtin_ast_add_build_target_attr(fn, kind) |
Mark fn as a [[cccc::build_target]] factory of the given kind.
| fn | The function object. |
| kind | The build-target kind string. |
| #define MarkAsTest | ( | fn | ) | AddAttribute(fn, "cccc::test") |
Shorthand for AddAttribute(fn, "cccc::test").
| fn | The function object. |
| #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.
| m | The member. |
| name | Attribute name. |
| i | Argument index. |
| #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.
| m | The member. |
| i | Use index. |
| j | Argument index. |
| #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.
| m | The member. |
| name | Attribute name. |
| #define MemberAttrArgCountAt | ( | m, | |
| i | |||
| ) | __builtin_ast_member_attr_arg_count_at(m, i) |
Return the argument count of attribute use i.
| m | The member. |
| i | Use index. |
| #define MemberAttrCount | ( | m | ) | __builtin_ast_member_attr_count(m) |
Return the number of custom attribute uses on the member.
| m | The member. |
| #define MemberAttrNameAt | ( | m, | |
| i | |||
| ) | __builtin_ast_member_attr_name_at(m, i) |
Return the name of attribute use i.
| m | The member. |
| i | Use index. |
| #define MemberBitfieldWidth | ( | m | ) | __builtin_ast_member_bitfield_width(m) |
Return the bit width of a bitfield member.
| m | The member to inspect. |
| #define MemberHasAttr | ( | m, | |
| name | |||
| ) | __builtin_ast_member_has_attr(m, name) |
Return 1 if the member carries the custom attribute name.
| m | The member. |
| name | Attribute name without the @. |
| #define MemberIsBitfield | ( | m | ) | __builtin_ast_member_is_bitfield(m) |
Test whether a member is a bitfield.
| m | The member to inspect. |
| #define MemberName | ( | m | ) | __builtin_ast_member_name(m) |
Return the name of a struct/union member.
| m | The member to inspect. |
| #define MemberOffset | ( | m | ) | __builtin_ast_member_offset(m) |
Return the byte offset of a struct/union member.
| m | The member to inspect. |
| #define MemberType | ( | m | ) | __builtin_ast_member_type(m) |
Return the type of a struct/union member.
| m | The member to inspect. |
| #define Memcpy | ( | dst, | |
| src, | |||
| n | |||
| ) |
Build a call node to memcpy(dst, src, n).
| dst | Destination expression. |
| src | Source expression. |
| n | Byte count expression. |
| #define NodeBody | ( | node | ) | __builtin_ast_node_body(node) |
Return the statement list of an NK_BLOCK or NK_STMT_EXPR.
| node | The node to inspect. |
| #define NodeCond | ( | node | ) | __builtin_ast_node_cond(node) |
Return the condition of an if, loop, switch or ?: node.
| node | The node to inspect. |
| #define NodeElse | ( | node | ) | __builtin_ast_node_else(node) |
Return the else-branch of an if or ?: node.
| node | The node to inspect. |
| #define NodeFloatValue | ( | node | ) | __builtin_ast_node_float_value(node) |
Return the value of a floating NK_NUM literal.
| node | The node to inspect. |
| #define NodeInc | ( | node | ) | __builtin_ast_node_inc(node) |
Return the increment of a for node.
| node | The node to inspect. |
| #define NodeInit | ( | node | ) | __builtin_ast_node_init(node) |
Return the initialiser of a for node.
| node | The node to inspect. |
| #define NodeIntValue | ( | node | ) | __builtin_ast_node_int_value(node) |
Return the value of an integer NK_NUM literal.
| node | The node to inspect. |
| #define NodeLhs | ( | node | ) | __builtin_ast_node_lhs(node) |
Return the left operand (or sole operand) of a node.
| node | The node to inspect. |
| #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.
| nodes | Array of Node* to link together. |
| count | Number of elements in the array. |
| #define NodeMember | ( | node | ) | __builtin_ast_node_member(node) |
Return the member an NK_MEMBER node selects.
| node | The node to inspect. |
| #define NodeNext | ( | node | ) | __builtin_ast_node_next(node) |
Return the next node in a statement or argument list.
| node | The node to inspect. |
| #define NodeRhs | ( | node | ) | __builtin_ast_node_rhs(node) |
Return the right operand of a node.
| node | The node to inspect. |
| #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.
| node | The node to inspect. |
| #define NodeVarObj | ( | node | ) | __builtin_ast_node_var_obj(node) |
Return the variable an NK_VAR (or NK_MEMZERO) node refers to.
| node | The node to inspect. |
| #define ObjIsDefinition | ( | obj | ) | __builtin_ast_obj_is_definition(obj) |
Test whether a global object has a definition.
| obj | The object to inspect. |
| #define ObjIsFunction | ( | obj | ) | __builtin_ast_obj_is_function(obj) |
Test whether a global object is a function.
| obj | The object to inspect. |
| #define ObjIsStatic | ( | obj | ) | __builtin_ast_obj_is_static(obj) |
Test whether a global object has internal (static) linkage.
| obj | The object to inspect. |
| #define ObjName | ( | obj | ) | __builtin_ast_obj_name(obj) |
Return the name of a global object.
| obj | The object to inspect. |
| #define ObjNext | ( | obj | ) | __builtin_ast_obj_next(obj) |
Return the next Obj in the list that holds obj.
| obj | A parameter, local or global Obj. |
| #define ObjType | ( | obj | ) | __builtin_ast_obj_type(obj) |
Return the type of a global object.
| obj | The object to inspect. |
| #define OffsetofChain | ( | type, | |
| ... | |||
| ) |
Compute the byte offset of a (possibly nested) member chain as a MakeIntLiteral AST node.
| type | The starting struct/union type. |
| ... | Member names to walk, innermost last. |
| #define OverflowOp | ( | node | ) | __builtin_ast_overflow_op(node) |
Return the operation (AST_OVERFLOW_*) of an NK_OVERFLOW_ARITH.
| node | An NK_OVERFLOW_ARITH node. |
| #define OverflowResultPtr | ( | node | ) | __builtin_ast_overflow_result_ptr(node) |
Return the result pointer of an NK_OVERFLOW_ARITH.
| node | An NK_OVERFLOW_ARITH node. |
| #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.
| p | The parameter type. |
| name | Attribute name. |
| i | Argument index. |
| #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.
| p | The parameter type. |
| i | Use index. |
| j | Argument index. |
| #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.
| p | The parameter type. |
| name | Attribute name. |
| #define ParamAttrArgCountAt | ( | p, | |
| i | |||
| ) | __builtin_ast_param_attr_arg_count_at(p, i) |
Return the argument count of attribute use i.
| p | The parameter type. |
| i | Use index. |
| #define ParamAttrCount | ( | p | ) | __builtin_ast_param_attr_count(p) |
Return the number of custom attribute uses on the parameter.
| p | The parameter type. |
| #define ParamAttrNameAt | ( | p, | |
| i | |||
| ) | __builtin_ast_param_attr_name_at(p, i) |
Return the name of attribute use i.
| p | The parameter type. |
| i | Use index. |
| #define ParamHasAttr | ( | p, | |
| name | |||
| ) | __builtin_ast_param_has_attr(p, name) |
Return 1 if the parameter carries the custom attribute name.
| p | The parameter type (from TypeParamAt). |
| name | Attribute name without the @. |
| #define PublishNode | ( | decl | ) |
Make a generated declaration visible at the current source position.
| decl | An 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.
| #define PublishNodeAt | ( | decl, | |
| tok | |||
| ) |
Like PublishNode, but attaches an explicit diagnostic token.
| decl | An Obj* (function/global) or Type* created by the AST builders. |
| tok | Representative token for diagnostics, or NULL. |
| #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.
| tmpl | A 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). |
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. | #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.
| tmpl | A 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). |
| #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.
| tmpl | Template string with $N / $@N splice points. |
| nodes | Array of Node* splice arguments. |
| count | Length of the nodes array. |
| #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.
| tmpl | Template string with $N / $@N splice points. |
| nodes | Array of Node* splice arguments. |
| count | Length of the nodes array. |
| #define Serialize | ( | ty, | |
| expr, | |||
| buf | |||
| ) | __builtin_ast_serialize(ty, expr, buf) |
Build a block of memcpy() calls copying expr (of type ty) into buf.
| ty | The type of expr. |
| expr | The expression to serialize. |
| buf | A 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.
| #define SetToken | ( | node, | |
| tok | |||
| ) | __builtin_ast_set_token(node, tok) |
Attach an opaque source token to node.
| node | Node to update. |
| tok | Token from CurrentToken(), SyntheticToken(), or TokenFromNode(). |
| #define Strcmp | ( | a, | |
| b | |||
| ) |
Build a call node to strcmp(a, b).
| a | First string expression. |
| b | Second string expression. |
| #define StringLiteralValue | ( | node | ) | __builtin_ast_string_literal_value(node) |
Return the text of a string literal node, or NULL.
| node | A node, typically a macro or attribute argument. |
| #define StripImplicit | ( | node | ) | __builtin_ast_node_strip_implicit(node) |
Peel compiler-inserted casts and call wrappers off a node.
| node | The node to inspect. |
| #define Strlen | ( | s | ) | __builtin_ast_funcall(__builtin_ast_var_ref("strlen"), (Node *[]){(s)}, 1) |
Build a call node to strlen(s).
| s | String expression. |
| #define StructAddField | ( | ... | ) |
Append a field to a struct or union and recompute its layout.
| ... | 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.
| #define StructMemberAt | ( | ty, | |
| i | |||
| ) | __builtin_ast_struct_member_at(ty, i) |
Return the member at the given index.
| ty | The struct or union type to inspect. |
| i | Zero-based member index. |
| #define StructMemberCount | ( | ty | ) | __builtin_ast_struct_member_count(ty) |
Return the number of members of a struct or union type.
| ty | The struct or union type to inspect. |
| #define StructMemberFind | ( | ty, | |
| name | |||
| ) | __builtin_ast_struct_member_find(ty, name) |
Look up a struct or union member by name.
| ty | The struct or union type to search. |
| name | The member name to look up. |
| #define SwitchAddCase | ( | ... | ) |
Append a case to a switch statement.
| ... | 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.
| #define SwitchCaseAt | ( | sw, | |
| i | |||
| ) | __builtin_ast_switch_case_at(sw, i) |
Return a case label of a switch, in source order.
| sw | An NK_SWITCH node. |
| i | Zero-based case index. |
| #define SwitchCaseCount | ( | sw | ) | __builtin_ast_switch_case_count(sw) |
Return the number of case labels of a switch (excluding default).
| sw | An NK_SWITCH node. |
| #define SwitchDefault | ( | sw | ) | __builtin_ast_switch_default(sw) |
Return the default label of a switch.
| sw | An NK_SWITCH node. |
| #define SwitchSetDefault | ( | ... | ) |
Set the default case for a switch statement.
| ... | Either (body) inside a WithSwitch(sw) block, or (sw, body) to name the switch explicitly. |
Dispatches on argument count via __builtin_dispatch_2.
| #define SyntheticToken | ( | label | ) | __builtin_ast_synthetic_token(label) |
Create an opaque synthetic source token for generated AST nodes.
| label | Short diagnostic label for the synthetic location. |
| #define TokenFromNode | ( | node | ) | __builtin_ast_token_from_node(node) |
Return the opaque source token attached to node.
| node | Node to inspect. |
| #define TypeAlign | ( | ty | ) | __builtin_ast_type_align(ty) |
Return _Alignof(ty) in bytes.
| ty | The type to inspect. |
| #define TypeArrayLen | ( | ty | ) | __builtin_ast_type_array_len(ty) |
Return the fixed length of an array type.
| ty | The array type to inspect. |
| #define TypeBase | ( | ty | ) | __builtin_ast_type_base(ty) |
Return the element type of a pointer or array.
| ty | The pointer/array type to inspect. |
| #define TypeCName | ( | ty | ) | __builtin_ast_type_c_name(ty) |
Return a valid C identifier fragment naming ty (for naming generated functions).
| ty | The type to inspect. |
| #define TypeExists | ( | name | ) | __builtin_ast_type_exists(name) |
Check whether a type is currently in scope by name.
| name | The type name to look up. |
| #define TypeIsConst | ( | ty | ) | __builtin_ast_type_is_const(ty) |
Test whether a type is const-qualified.
| ty | The type to inspect. |
| #define TypeIsUnsigned | ( | ty | ) | __builtin_ast_type_is_unsigned(ty) |
Test whether an integer type is unsigned.
| ty | The type to inspect. |
| #define TypeIsVariadic | ( | ty | ) | __builtin_ast_type_is_variadic(ty) |
Test whether a function type is variadic.
| ty | The type to inspect. |
| #define TypeName | ( | ty | ) | __builtin_ast_type_name(ty) |
Return the user-visible name of a type, if any.
| ty | The type to inspect. |
| #define TypeParamAt | ( | ty, | |
| i | |||
| ) | __builtin_ast_type_param_at(ty, i) |
Return the type of the parameter at the given index.
| ty | The function type to inspect. |
| i | Zero-based parameter index. |
| #define TypeParamCount | ( | ty | ) | __builtin_ast_type_param_count(ty) |
Return the number of declared parameters of a function type.
| ty | The function type to inspect. |
| #define TypeReturnType | ( | ty | ) | __builtin_ast_type_return_type(ty) |
Return the return type of a function type.
| ty | The function type to inspect. |
| #define TypeSize | ( | ty | ) | __builtin_ast_type_size(ty) |
Return sizeof(ty) in bytes.
| ty | The type to inspect. |
| #define VarargAsArray | ( | ) | __builtin_ast_varargs_as_array() |
Return an inline macro's variadic AST arguments as a borrowed array.
| #define VarargAt | ( | i | ) | __builtin_ast_vararg_at(i) |
Return an inline macro's variadic AST argument by zero-based index.
| i | Zero-based variadic argument index. |
| #define VarargCount | ( | ) | __builtin_ast_vararg_count() |
Return the number of variadic arguments for the active macro call.
| #define VarargStrAt | ( | i | ) | __builtin_ast_vararg_str_at(i) |
Return a global-generation macro's stringified variadic argument by index.
| i | Zero-based variadic argument index. |
| #define WithBlock | ( | block | ) |
Block helper: establishes block as the current statement-append context so BlockAddStmt(stmt) appends to it.
| block | The 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.
| #define WithEnum | ( | ty | ) |
Block helper: establishes ty as the current constant-add context so EnumAddConstant(name, value) appends to it.
| ty | The enum type being populated. |
Implemented as a single-iteration for loop; use continue rather than break to exit early so the pop still runs.
| #define WithFn | ( | fn | ) |
Block helper: establishes fn as the current function-building context so Quote("return x;") applies the correct return-type cast.
| fn | The 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.
| #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.
| loop | A loop node returned by MakeWhile/MakeFor/MakeDoWhile. |
| #define WithStruct | ( | ty | ) |
Block helper: establishes ty as the current field-add context so StructAddField(name, ty) appends to it.
| ty | The aggregate type being populated. |
Implemented as a single-iteration for loop; use continue rather than break to exit early so the pop still runs.
| #define WithSwitch | ( | sw | ) |
Block helper: establishes sw as the current case/default context so SwitchAddCase / SwitchSetDefault populate it.
| sw | The switch node being populated. |
Implemented as a single-iteration for loop; use continue rather than break to exit early so the pop still runs.
| 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 | |
| enum AstJumpKind |
Which statement an NK_GOTO node came from, returned by GotoJumpKind(node).
| Enumerator | |
|---|---|
| AST_JUMP_GOTO | |
| AST_JUMP_BREAK | |
| AST_JUMP_CONTINUE | |
| enum AstOverflowOp |
The operation of an NK_OVERFLOW_ARITH node, returned by OverflowOp(node).
| Enumerator | |
|---|---|
| AST_OVERFLOW_ADD | |
| AST_OVERFLOW_SUB | |
| AST_OVERFLOW_MUL | |
| enum 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 | |
| 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.
| 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 | |
| void __builtin_ast_add_attribute | ( | Obj * | fn, |
| const char * | attr_text | ||
| ) |
Apply an attribute string to a programmatically created function.
| fn | The function object to attribute (created by MakeFunction). |
| attr_text | Attribute 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).
| void __builtin_ast_add_build_target_attr | ( | Obj * | fn, |
| const char * | kind | ||
| ) |
| Node * __builtin_ast_alignof_type | ( | Type * | ty | ) |
Emit _Alignof(ty) as a compile-time integer literal.
| ty | The type to measure. |
Convenience wrapper: MakeAlignofType(ty).
| const char * __builtin_ast_asm_clobber_at | ( | Node * | node, |
| int | index | ||
| ) |
Return a clobber of an NK_ASM statement.
| node | An NK_ASM node. |
| index | Zero-based clobber index. |
Convenience wrapper: AsmClobberAt(node, i).
| int __builtin_ast_asm_clobber_count | ( | Node * | node | ) |
Return the number of clobbers of an NK_ASM statement.
| node | An NK_ASM node. |
Convenience wrapper: AsmClobberCount(node).
| const char * __builtin_ast_asm_goto_label_at | ( | Node * | node, |
| int | index | ||
| ) |
Return a jump label name of an asm goto.
| node | An NK_ASM node. |
| index | Zero-based label index. |
Convenience wrapper: AsmGotoLabelAt(node, i).
| int __builtin_ast_asm_goto_label_count | ( | Node * | node | ) |
Return the number of jump labels of an asm goto.
| node | An NK_ASM node. |
Convenience wrapper: AsmGotoLabelCount(node).
| int __builtin_ast_asm_input_count | ( | Node * | node | ) |
Return the number of input operands of an NK_ASM statement.
| node | An NK_ASM node. |
Convenience wrapper: AsmInputCount(node).
| bool __builtin_ast_asm_is_goto | ( | Node * | node | ) |
Return whether an NK_ASM statement is an asm goto.
| node | An NK_ASM node. |
asm goto, false otherwise.Convenience wrapper: AsmIsGoto(node).
| bool __builtin_ast_asm_is_volatile | ( | Node * | node | ) |
Return whether an NK_ASM statement is written volatile.
| node | An NK_ASM node. |
Convenience wrapper: AsmIsVolatile(node).
| const char * __builtin_ast_asm_operand_constraint | ( | Node * | node, |
| int | index | ||
| ) |
Return the constraint string of an asm operand.
| node | An NK_ASM node. |
| index | Zero-based operand index; outputs come before inputs. |
Convenience wrapper: AsmOperandConstraint(node, i).
| Node * __builtin_ast_asm_operand_expr | ( | Node * | node, |
| int | index | ||
| ) |
Return the expression of an asm operand.
| node | An NK_ASM node. |
| index | Zero-based operand index; outputs come before inputs. |
Convenience wrapper: AsmOperandExpr(node, i).
| const char * __builtin_ast_asm_operand_name | ( | Node * | node, |
| int | index | ||
| ) |
Return the symbolic name of an asm operand.
| node | An NK_ASM node. |
| index | Zero-based operand index; outputs come before inputs. |
[name], or NULL when unnamed or out of range.Convenience wrapper: AsmOperandName(node, i).
| int __builtin_ast_asm_output_count | ( | Node * | node | ) |
Return the number of output operands of an NK_ASM statement.
| node | An NK_ASM node. |
Convenience wrapper: AsmOutputCount(node).
| const char * __builtin_ast_asm_template | ( | Node * | node | ) |
Return the template string of an NK_ASM statement.
| node | An NK_ASM node. |
Convenience wrapper: AsmTemplate(node).
| Node * __builtin_ast_assign | ( | Node * | target, |
| Node * | value | ||
| ) |
Build an assignment node (target = value).
| target | The lvalue expression being assigned to. |
| value | The rvalue expression to assign. |
Convenience wrapper: MakeAssign(target, value).
| int __builtin_ast_atomic_fail_order | ( | Node * | node | ) |
Return the failure memory order of an NK_CAS.
| node | An NK_CAS node. |
__ATOMIC_* value, as AtomicOrder; -1 for other kinds.Convenience wrapper: AtomicFailOrder(node).
| bool __builtin_ast_atomic_is_weak | ( | Node * | node | ) |
Return whether an NK_CAS was written as a weak compare-exchange.
| node | An NK_CAS node. |
Convenience wrapper: AtomicIsWeak(node).
| int __builtin_ast_atomic_order | ( | Node * | node | ) |
Return the memory order of an NK_CAS, NK_EXCH, NK_ALOAD or NK_ASTORE.
| node | The node to inspect. |
__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).
| Node * __builtin_ast_binary | ( | NodeKind | op, |
| Node * | left, | ||
| Node * | right | ||
| ) |
Build a binary operation AST node.
| op | The operator kind (NK_ADD, NK_SUB, ...). |
| left | The left-hand operand. |
| right | The right-hand operand. |
Convenience wrapper: MakeBinary(op, left, right).
| int __builtin_ast_bitop_op | ( | Node * | node | ) |
Return the operation of an NK_BITOP.
| node | An NK_BITOP node. |
Convenience wrapper: BitopOp(node).
| int __builtin_ast_bitop_width | ( | Node * | node | ) |
Return the bit width of an NK_BITOP's builtin.
| node | An NK_BITOP node. |
Convenience wrapper: BitopWidth(node).
| Node * __builtin_ast_block | ( | Node ** | stmts, |
| int | count | ||
| ) |
Build a block (compound statement) node.
| stmts | Array of statement nodes, or NULL if count is 0. |
| count | Number of statements in the array. |
Convenience wrapper: MakeBlock(stmts, count).
| Node * __builtin_ast_block_add_current_stmt | ( | Node * | stmt | ) |
| Node * __builtin_ast_block_add_stmt | ( | Node * | block, |
| Node * | stmt | ||
| ) |
Append a statement to a block node.
| block | The NK_BLOCK node to modify. |
| stmt | The statement to append. |
Convenience wrapper: BlockAddStmt(block, stmt), or BlockAddStmt(stmt) inside WithBlock(block).
| Node * __builtin_ast_block_at | ( | Node * | block, |
| int | index | ||
| ) |
Return a statement of an NK_BLOCK or NK_STMT_EXPR.
| block | The block node. |
| index | Zero-based statement index. |
Convenience wrapper: BlockAt(block, i).
| int __builtin_ast_block_count | ( | Node * | block | ) |
Return the number of statements in an NK_BLOCK or NK_STMT_EXPR.
| block | The block node. |
Convenience wrapper: BlockCount(block).
| Node * __builtin_ast_call_arg_at | ( | Node * | call, |
| int | index | ||
| ) |
Return an argument of a call.
| call | An NK_FUNCALL node (or the comma wrapper around one). |
| index | Zero-based argument index. |
Convenience wrapper: CallArgAt(call, i).
| int __builtin_ast_call_arg_count | ( | Node * | call | ) |
Return the number of arguments of a call.
| call | An NK_FUNCALL node (or the comma wrapper around one). |
Convenience wrapper: CallArgCount(call).
| Node * __builtin_ast_call_callee | ( | Node * | call | ) |
Return the callee expression of a call.
| call | An NK_FUNCALL node (or the comma wrapper around one). |
Convenience wrapper: CallCallee(call).
| Node * __builtin_ast_cas_addr | ( | Node * | node | ) |
Return the address operand of an NK_CAS.
| node | An NK_CAS node. |
Convenience wrapper: CasAddr(node).
| Node * __builtin_ast_cas_desired | ( | Node * | node | ) |
Return the desired-value operand of an NK_CAS.
| node | An NK_CAS node. |
Convenience wrapper: CasDesired(node).
| Node * __builtin_ast_cas_expected | ( | Node * | node | ) |
Return the expected-value operand of an NK_CAS.
| node | An NK_CAS node. |
Convenience wrapper: CasExpected(node).
| long long __builtin_ast_case_begin | ( | Node * | node | ) |
Return the first value of an NK_CASE label.
| node | An NK_CASE node. |
Convenience wrapper: CaseBegin(node).
| Node * __builtin_ast_case_body | ( | Node * | node | ) |
Return the statement that follows an NK_CASE label.
| node | An NK_CASE node. |
Convenience wrapper: CaseBody(node).
| 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 | An NK_CASE node. |
Convenience wrapper: CaseEnd(node).
| Node * __builtin_ast_cast | ( | Node * | expr, |
| Type * | target_type | ||
| ) |
Build a type cast AST node.
| expr | The expression to cast. |
| target_type | The type to cast to. |
Convenience wrapper: MakeCast(expr, target_type).
| Node * __builtin_ast_comma | ( | Node * | lhs, |
| Node * | rhs | ||
| ) |
Build a comma expression: evaluate lhs, yield rhs.
| lhs | The expression evaluated for side effects. |
| rhs | The expression whose value is the result. |
Convenience wrapper: MakeComma(lhs, rhs).
| 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_cond | ( | Node * | cond, |
| Node * | then_expr, | ||
| Node * | else_expr | ||
| ) |
Build a ternary conditional expression node (cond ? then : else).
| cond | The condition expression. |
| then_expr | The expression evaluated when cond is non-zero. |
| else_expr | The expression evaluated when cond is zero. |
Convenience wrapper: MakeCond(cond, then_expr, else_expr).
| bool __builtin_ast_const_int_value | ( | Node * | node, |
| int64_t * | out | ||
| ) |
Evaluate an integer constant expression node.
| node | A node, typically a macro or attribute argument. |
| out | Receives the value when the result is true. |
3, -1, 2 * N, an enum constant), false otherwise.Convenience wrapper: ConstIntValue(node, &out).
| bool __builtin_ast_const_uint_value | ( | Node * | node, |
| uint64_t * | out | ||
| ) |
Evaluate an unsigned integer constant expression node.
| node | A node, typically a macro or attribute argument. |
| out | Receives the value when the result is true. |
INT64_MAX such as 18446744073709551615ULL is accepted.Convenience wrapper: ConstUIntValue(node, &out).
| Node * __builtin_ast_copy_location | ( | Node * | dst, |
| Node * | src | ||
| ) |
Copy the source token from one node to another.
| dst | Generated node to update. |
| src | Source node whose location should be reused. |
Convenience wrapper: CopyLocation(dst, src).
| Node * __builtin_ast_copy_node | ( | Node * | n | ) |
Deep-copy an expression or statement tree.
| n | Node to copy. |
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.
| Token * __builtin_ast_current_token | ( | void | ) |
Return the token for the macro invocation currently being executed.
Convenience wrapper: CurrentToken().
| 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.
| Node * __builtin_ast_do_while | ( | Node * | body, |
| Node * | cond | ||
| ) |
Create a do-while loop node.
| body | The loop body, or NULL to attach one later with LoopSetBody. |
| cond | The loop condition (tested after each iteration). |
Convenience wrapper: MakeDoWhile(body, cond). See MakeWhile for break/continue target details.
| 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.
| ty | The enum type. |
| name | The constant name. |
| value | The 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).
| void __builtin_ast_enum_add_current_constant | ( | const char * | name, |
| int | value | ||
| ) |
| EnumConstant * __builtin_ast_enum_at | ( | Type * | enum_type, |
| int | index | ||
| ) |
Return the enum constant at a given index.
| enum_type | The enum type to inspect. |
| index | Zero-based index. |
Convenience wrapper: EnumAt(ty, index).
| const char * __builtin_ast_enum_constant_name | ( | EnumConstant * | ec | ) |
Return the name of an enum constant.
| ec | The enum constant. |
Convenience wrapper: EnumConstantName(ec).
| int64_t __builtin_ast_enum_constant_value | ( | EnumConstant * | ec | ) |
Return the integer value of an enum constant.
| ec | The enum constant. |
Convenience wrapper: EnumConstantValue(ec).
| int __builtin_ast_enum_count | ( | Type * | enum_type | ) |
Return the number of constants in an enum type.
| enum_type | The enum type to inspect. |
Convenience wrapper: EnumCount(ty).
| EnumConstant * __builtin_ast_enum_find | ( | Type * | enum_type, |
| const char * | name | ||
| ) |
Look up an enum constant by name.
| enum_type | The enum type to search. |
| name | The constant name to look up. |
Convenience wrapper: EnumFind(ty, name).
| 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.
| ty | The enum type. |
| expr | The expression to compare (a const char *). |
Convenience wrapper: EnumFromString(ty, expr).
| const char * __builtin_ast_enum_name | ( | Type * | e | ) |
Return the tag name of an enum type.
| e | The enum type to inspect. |
Convenience wrapper: EnumName(ty).
| 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.
| ty | The enum type. |
| expr | The expression to switch on (the enum value). |
const char *.Convenience wrapper: EnumToString(ty, expr).
| int64_t __builtin_ast_enum_value | ( | Type * | e, |
| int | index | ||
| ) |
Return the integer value of the enum constant at the given index.
| e | The enum type to inspect. |
| index | Zero-based index. |
Convenience wrapper: EnumValue(ty, index).
| int __builtin_ast_enum_value_count | ( | Type * | e | ) |
Return the number of values in an enum type.
| e | The enum type to inspect. |
Convenience wrapper: EnumValueCount(ty).
| const char * __builtin_ast_enum_value_name | ( | Type * | e, |
| int | index | ||
| ) |
Return the name of the enum constant at the given index.
| e | The enum type to inspect. |
| index | Zero-based index. |
Convenience wrapper: EnumValueName(ty, index).
| Node * __builtin_ast_expr_stmt | ( | Node * | expr | ) |
Build an expression statement node.
| expr | The expression to evaluate for side effects. |
Convenience wrapper: MakeExprStmt(expr).
| bool __builtin_ast_fence_is_signal | ( | Node * | node | ) |
Return whether an NK_FENCE is a signal fence.
| node | An NK_FENCE node. |
Convenience wrapper: FenceIsSignal(node).
| Obj * __builtin_ast_find_global | ( | const char * | name | ) |
Look up a global symbol by name.
| name | The global name to look up. |
Convenience wrapper: FindGlobal(name).
| Type * __builtin_ast_find_type | ( | const char * | name | ) |
Look up a type by tag name (struct/union/enum).
| name | The tag name to look up. |
Convenience wrapper: FindType(name).
| Node * __builtin_ast_float_literal | ( | double | value | ) |
Build a floating-point literal AST node.
| value | The floating-point value. |
Convenience wrapper: MakeFloatLiteral(value).
| Node * __builtin_ast_for | ( | Node * | init, |
| Node * | cond, | ||
| Node * | inc, | ||
| Node * | body | ||
| ) |
Create a for loop node.
| init | Initialiser expression/statement (may be NULL). |
| cond | Loop condition (may be NULL for infinite loop). |
| inc | Increment expression (may be NULL). |
| body | Loop body, or NULL to attach one later with LoopSetBody. |
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.
| Node * __builtin_ast_funcall | ( | Node * | callee, |
| Node ** | args, | ||
| int | n | ||
| ) |
Create a function call node.
| callee | An expression node that evaluates to a function (or function pointer). The callee's lhs field holds this expression. |
| args | Array of argument nodes (may be NULL if n == 0). |
| n | Number of arguments. |
Convenience wrapper: MakeFuncCall(callee, args, n).
| Obj * __builtin_ast_function | ( | const char * | name, |
| Type * | return_type | ||
| ) |
Create a new function object.
| name | The function name. |
| return_type | The return type. |
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).
| void __builtin_ast_function_add_param | ( | Obj * | fn, |
| const char * | name, | ||
| Type * | type | ||
| ) |
Add a parameter to a function.
| fn | The function object. |
| name | The parameter name. |
| type | The parameter type. |
Parameters are added in order. Call this multiple times for multiple parameters. Convenience wrapper: FunctionAddParam(fn, name, type).
| Node * __builtin_ast_function_body | ( | Obj * | fn | ) |
Return the top-level block of a function definition.
| fn | A function Obj. |
Convenience wrapper: FnBody(fn).
| Obj * __builtin_ast_function_local_at | ( | Obj * | fn, |
| int | index | ||
| ) |
Return a local variable of a function definition, in declaration order.
| fn | A function Obj. |
| index | Zero-based local index. |
Convenience wrapper: FnLocalAt(fn, i).
| int __builtin_ast_function_local_count | ( | Obj * | fn | ) |
Return the number of source-level locals of a function definition.
| fn | A function Obj. |
Convenience wrapper: FnLocalCount(fn).
| Obj * __builtin_ast_function_param_at | ( | Obj * | fn, |
| int | index | ||
| ) |
Return a parameter of a function definition, in declaration order.
| fn | A function Obj. |
| index | Zero-based parameter index. |
Convenience wrapper: FnParamAt(fn, i).
| int __builtin_ast_function_param_count | ( | Obj * | fn | ) |
Return the number of parameters of a function definition.
| fn | A function Obj. |
Convenience wrapper: FnParamCount(fn).
| Obj * __builtin_ast_function_prototype | ( | const char * | name, |
| Type * | return_type | ||
| ) |
Create a function forward declaration (prototype) without a body.
| name | The function name. |
| return_type | The return type. |
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).
| void __builtin_ast_function_set_body | ( | Obj * | fn, |
| Node * | body | ||
| ) |
Set the body of a function.
| fn | The function object. |
| body | The 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).
| void __builtin_ast_function_set_inline | ( | Obj * | fn, |
| bool | is_inline | ||
| ) |
Set whether a function is inline.
| fn | The function object. |
| is_inline | True for inline, false otherwise. |
Convenience wrapper: FunctionSetInline(fn, is_inline).
| void __builtin_ast_function_set_static | ( | Obj * | fn, |
| bool | is_static | ||
| ) |
Set whether a function has static linkage.
| fn | The function object. |
| is_static | True for static linkage, false for external. |
Convenience wrapper: FunctionSetStatic(fn, is_static).
| void __builtin_ast_function_set_variadic | ( | Obj * | fn, |
| bool | is_variadic | ||
| ) |
Set whether a function is variadic.
| fn | The function object. |
| is_variadic | True for variadic, false otherwise. |
Convenience wrapper: FunctionSetVariadic(fn, is_variadic).
| Type * __builtin_ast_get_type | ( | const char * | name | ) |
Look up a type by name, resolving standard base-type spellings.
| name | The 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. |
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).
| Obj * __builtin_ast_global_at | ( | int | index | ) |
Return the global symbol at the given index.
| index | Zero-based global index. |
Convenience wrapper: GlobalAt(index).
| int __builtin_ast_global_count | ( | void | ) |
Return the total number of global symbols.
Convenience wrapper: GlobalCount().
| Obj * __builtin_ast_global_var | ( | const char * | name, |
| Type * | ty | ||
| ) |
Create a new named global variable definition.
| name | The variable name (must be unique among globals). |
| ty | The variable type. Use MakeArray(char_ty, len) for byte arrays so that the size matches the init_data length. |
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).
| void __builtin_ast_global_var_set_init_data | ( | Obj * | var, |
| const char * | data, | ||
| int | len | ||
| ) |
Set the initial data for a generated global variable.
| var | The global variable object. |
| data | Pointer to the raw byte data. |
| len | Number of bytes to copy. Must equal var->ty->size. |
Convenience wrapper: GlobalVarSetInitData(var, data, len).
| void __builtin_ast_global_var_set_static | ( | Obj * | var, |
| bool | is_static | ||
| ) |
Set the static (internal linkage) flag on a generated global.
| var | The global variable object. |
| is_static | True for internal linkage (file-scope static). |
Convenience wrapper: GlobalVarSetStatic(var, is_static).
| int __builtin_ast_goto_jump_kind | ( | Node * | node | ) |
Return which statement an NK_GOTO came from.
| node | The node to inspect. |
Convenience wrapper: GotoJumpKind(node).
| Node * __builtin_ast_if | ( | Node * | cond, |
| Node * | then_body, | ||
| Node * | else_body | ||
| ) |
Build an if statement node.
| cond | The condition expression. |
| then_body | The body executed when cond is non-zero. |
| else_body | The body executed when cond is zero, or NULL. |
Convenience wrapper: MakeIf(cond, then_body, else_body).
| 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_int_literal | ( | int64_t | value | ) |
Build an integer literal AST node.
| value | The integer value. |
Convenience wrapper: MakeIntLiteral(value).
| const char * __builtin_ast_label_name | ( | Node * | node | ) |
Return the name of an NK_GOTO, NK_LABEL or NK_LABEL_VAL.
| node | The node to inspect. |
Convenience wrapper: LabelName(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.
| name | The variable name (user-visible). |
| ty | The variable type. |
Convenience wrapper: MakeLocalVar(name, ty).
| 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.
| ty | The variable type. |
Convenience wrapper: MakeLocalVarUnique(ty).
| Node * __builtin_ast_loop_set_body | ( | Node * | loop, |
| Node * | body | ||
| ) |
Attach body to loop (a node from MakeWhile/MakeFor/MakeDoWhile).
| loop | The loop node to attach the body to. |
| body | The loop body statement; a QuoteLazy() fragment is expanded in loop's own context. |
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.
| Node * __builtin_ast_macro_call_arg_at | ( | Node * | node, |
| int | index | ||
| ) |
Return an argument of an NK_MACRO_CALL.
| node | The node to inspect. |
| index | Zero-based argument index. |
Convenience wrapper: MacroCallArgAt(node, i).
| int __builtin_ast_macro_call_arg_count | ( | Node * | node | ) |
Return the argument count of an NK_MACRO_CALL.
| node | The node to inspect. |
Convenience wrapper: MacroCallArgCount(node).
| const char * __builtin_ast_macro_call_name | ( | Node * | node | ) |
Return the macro name of a not-yet-expanded NK_MACRO_CALL.
| node | The node to inspect. |
Convenience wrapper: MacroCallName(node).
| Type * __builtin_ast_make_array | ( | Type * | base, |
| int | length | ||
| ) |
Build a fixed-length array type.
| base | The element type. |
| length | The element count. |
Convenience wrapper: MakeArray(base, length).
| Type * __builtin_ast_make_const | ( | Type * | ty | ) |
Return a const-qualified copy of ty.
| ty | The type to qualify. |
Convenience wrapper: MakeConst(ty).
| Type * __builtin_ast_make_enum | ( | const char * | name | ) |
Create and expose a new named enum type.
| name | The enum tag name. |
Use EnumAddConstant to add constants after creation. Convenience wrapper: MakeEnum(name).
| 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)".
| return_ty | The function's return type. |
| param_types | Array of parameter types (each copy_type()'d internally). |
| nparams | Number of entries in param_types (max 16). |
Convenience wrapper: MakeFuncPtrType(return_ty, param_types, nparams).
| Type * __builtin_ast_make_pointer | ( | Type * | base | ) |
Build a pointer-to-base type.
| base | The pointed-to type. |
Convenience wrapper: MakePointer(base).
| Type * __builtin_ast_make_struct | ( | const char * | name | ) |
Create and expose a new named struct type.
| name | The struct tag name. |
Use StructAddField to add fields after creation. The type is immediately visible via FindType(name). Convenience wrapper: MakeStruct(name).
| Type * __builtin_ast_make_typedef | ( | const char * | name, |
| Type * | underlying | ||
| ) |
Register a typedef alias for a type and expose it in scope.
| name | The typedef name. |
| underlying | The aliased type. |
After this call, FindType(name) resolves to underlying and subsequently compiled code can use name as a type name. Convenience wrapper: MakeTypedef(name, underlying).
| Type * __builtin_ast_make_union | ( | const char * | name | ) |
Create and expose a new named union type.
| name | The union tag name. |
Convenience wrapper: MakeUnion(name).
| Type * __builtin_ast_make_volatile | ( | Type * | ty | ) |
Return a volatile-qualified copy of ty.
| ty | The type to qualify. |
Convenience wrapper: MakeVolatile(ty).
| Node * __builtin_ast_member | ( | Node * | obj, |
| const char * | name | ||
| ) |
Create a struct/union member access node (obj.name).
| obj | An expression node whose type must be a struct or union. |
| name | The member name as a NUL-terminated string. |
Convenience wrapper: MakeMember(obj, name).
| 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.
| 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_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.
| 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.
| 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_bitfield_width | ( | Member * | m | ) |
Return the bit width of a bitfield member.
| m | The member to inspect. |
Convenience wrapper: MemberBitfieldWidth(m).
| int __builtin_ast_member_has_attr | ( | Member * | m, |
| const char * | name | ||
| ) |
Return 1 if the member carries the custom attribute name.
| bool __builtin_ast_member_is_bitfield | ( | Member * | m | ) |
Test whether a member is a bitfield.
| m | The member to inspect. |
Convenience wrapper: MemberIsBitfield(m).
| const char * __builtin_ast_member_name | ( | Member * | m | ) |
Return the name of a struct/union member.
| m | The member to inspect. |
Convenience wrapper: MemberName(m).
| int __builtin_ast_member_offset | ( | Member * | m | ) |
Return the byte offset of a struct/union member.
| m | The member to inspect. |
Convenience wrapper: MemberOffset(m).
| Type * __builtin_ast_member_type | ( | Member * | m | ) |
Return the type of a struct/union member.
| m | The member to inspect. |
Convenience wrapper: MemberType(m).
| Node * __builtin_ast_node_body | ( | Node * | node | ) |
Return the statement list of an NK_BLOCK or NK_STMT_EXPR.
| node | The node to inspect. |
Convenience wrapper: NodeBody(node).
| Node * __builtin_ast_node_cond | ( | Node * | node | ) |
Return the condition of an if, loop, switch or ?: node.
| node | The node to inspect. |
Convenience wrapper: NodeCond(node).
| Node * __builtin_ast_node_else | ( | Node * | node | ) |
Return the else-branch of an if or ?: node.
| node | The node to inspect. |
Convenience wrapper: NodeElse(node).
| double __builtin_ast_node_float_value | ( | Node * | node | ) |
Return the value of a floating NK_NUM literal.
| node | The node to inspect. |
Convenience wrapper: NodeFloatValue(node).
| Node * __builtin_ast_node_inc | ( | Node * | node | ) |
Return the increment of a for node.
| node | The node to inspect. |
Convenience wrapper: NodeInc(node).
| Node * __builtin_ast_node_init | ( | Node * | node | ) |
Return the initialiser of a for node.
| node | The node to inspect. |
Convenience wrapper: NodeInit(node).
| long long __builtin_ast_node_int_value | ( | Node * | node | ) |
Return the value of an integer NK_NUM literal.
| node | The node to inspect. |
Convenience wrapper: NodeIntValue(node).
| NodeKind __builtin_ast_node_kind | ( | Node * | node | ) |
Return the kind of a node.
| node | The node to inspect. |
Convenience wrapper: GetNodeKind(node).
| Node * __builtin_ast_node_lhs | ( | Node * | node | ) |
Return the left operand (or sole operand) of a node.
| node | The node to inspect. |
Convenience wrapper: NodeLhs(node).
| Member * __builtin_ast_node_member | ( | Node * | node | ) |
Return the member an NK_MEMBER node selects.
| node | The node to inspect. |
Convenience wrapper: NodeMember(node).
| Node * __builtin_ast_node_next | ( | Node * | node | ) |
Return the next node in a statement or argument list.
| node | The node to inspect. |
Convenience wrapper: NodeNext(node).
| Node * __builtin_ast_node_rhs | ( | Node * | node | ) |
Return the right operand of a node.
| node | The node to inspect. |
Convenience wrapper: NodeRhs(node).
| Node * __builtin_ast_node_strip_implicit | ( | Node * | node | ) |
Peel compiler-inserted casts and call wrappers off a node.
| node | The node to inspect. |
(T)x casts stay.Convenience wrapper: StripImplicit(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 | The node to inspect. |
Convenience wrapper: NodeThen(node).
| Type * __builtin_ast_node_type | ( | Node * | node | ) |
Return the resolved type of an expression node.
| node | The node to inspect. |
Convenience wrapper: GetNodeType(node).
| Obj * __builtin_ast_node_var_obj | ( | Node * | node | ) |
Return the variable an NK_VAR (or NK_MEMZERO) node refers to.
| node | The node to inspect. |
Convenience wrapper: NodeVarObj(node).
| Node * __builtin_ast_null | ( | void | ) |
Build a typed null pointer node: (void *)0.
Convenience wrapper: MakeNull().
| bool __builtin_ast_obj_is_definition | ( | Obj * | obj | ) |
Test whether a global object has a definition.
| obj | The object to inspect. |
Convenience wrapper: ObjIsDefinition(obj).
| bool __builtin_ast_obj_is_function | ( | Obj * | obj | ) |
Test whether a global object is a function.
| obj | The object to inspect. |
Convenience wrapper: ObjIsFunction(obj).
| bool __builtin_ast_obj_is_static | ( | Obj * | obj | ) |
Test whether a global object has internal (static) linkage.
| obj | The object to inspect. |
Convenience wrapper: ObjIsStatic(obj).
| const char * __builtin_ast_obj_name | ( | Obj * | obj | ) |
Return the name of a global object.
| obj | The object to inspect. |
Convenience wrapper: ObjName(obj).
| Obj * __builtin_ast_obj_next | ( | Obj * | obj | ) |
Return the next Obj in the list that holds obj.
| obj | A parameter, local or global Obj. |
Convenience wrapper: ObjNext(obj).
| Type * __builtin_ast_obj_type | ( | Obj * | obj | ) |
Return the type of a global object.
| obj | The object to inspect. |
Convenience wrapper: ObjType(obj).
| int64_t __builtin_ast_offsetof_chain | ( | Type * | ty, |
| const char ** | names, | ||
| int | n | ||
| ) |
Compute the byte offset of a (possibly nested) member chain.
| ty | The starting struct/union type. |
| names | An array of member names to walk, innermost last. |
| n | The number of names in the chain. |
Convenience wrapper: OffsetofChain(ty, "a", "b", ...).
| int __builtin_ast_overflow_op | ( | Node * | node | ) |
Return the operation of an NK_OVERFLOW_ARITH.
| node | An NK_OVERFLOW_ARITH node. |
Convenience wrapper: OverflowOp(node).
| Node * __builtin_ast_overflow_result_ptr | ( | Node * | node | ) |
Return the result pointer of an NK_OVERFLOW_ARITH.
| node | An NK_OVERFLOW_ARITH node. |
Convenience wrapper: OverflowResultPtr(node).
| 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.
| 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.
| 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.
| 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.
| 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_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.
| Node * __builtin_ast_param_ref | ( | Obj * | fn, |
| const char * | name | ||
| ) |
Build a reference to a function parameter by name.
| fn | The function object whose parameter is being referenced. |
| name | The parameter name. |
Use this when building function bodies to reference parameters by name. Convenience wrapper: MakeParamRef(fn, name).
| void __builtin_ast_pop_block | ( | void | ) |
| void __builtin_ast_pop_enum | ( | void | ) |
| 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.
| 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.
| void __builtin_ast_pop_struct | ( | void | ) |
| void __builtin_ast_pop_switch | ( | void | ) |
| Node * __builtin_ast_publish | ( | Obj * | obj, |
| Token * | tok | ||
| ) |
Make a generated object visible at the current source position.
| obj | A function or global variable object created by the AST builders. |
| tok | Optional representative token for diagnostics, or NULL. |
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).
| Node * __builtin_ast_publish_type | ( | Type * | ty, |
| Token * | tok | ||
| ) |
Accept a generated type declaration as already published.
| ty | A type created by MakeStruct, MakeUnion, MakeEnum, or MakeTypedef. |
| tok | Optional representative token for diagnostics, or NULL. |
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.
| void __builtin_ast_push_block | ( | Node * | block | ) |
Establish a block as the current statement-append context.
| block | The NK_BLOCK node being populated. |
Use with WithBlock(block) so BlockAddStmt(stmt) appends to block without repeating the block pointer.
| void __builtin_ast_push_enum | ( | Type * | ty | ) |
Establish an enum as the current constant-add context.
| ty | The enum type being populated. |
Use with WithEnum(ty) so EnumAddConstant(name, value) appends to the current enum.
| 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.
| fn | The 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.
| 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.
| loop | A 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.
| void __builtin_ast_push_struct | ( | Type * | ty | ) |
Establish a struct or union as the current field-add context.
| ty | The aggregate type being populated. |
Use with WithStruct(ty) so StructAddField(name, ty) appends to the current aggregate.
| void __builtin_ast_push_switch | ( | Node * | switch_node | ) |
Establish a switch node as the current case/default context.
| switch_node | The switch node being populated. |
Use with WithSwitch(sw) so SwitchAddCase(value, body) and SwitchSetDefault(body) append to the current switch.
| Node * __builtin_ast_return | ( | Node * | expr | ) |
Build a return statement node.
| expr | The value to return (may be NULL for return; in void functions). |
Convenience wrapper: MakeReturn(expr).
| 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_set_token | ( | Node * | node, |
| Token * | tok | ||
| ) |
Attach an opaque source token to a node.
| node | Node to update. |
| tok | Token from __builtin_ast_current_token(), __builtin_ast_synthetic_token(), or __builtin_ast_token_from_node(). |
Convenience wrapper: SetToken(node, tok).
| Node * __builtin_ast_sizeof_expr | ( | Node * | expr | ) |
Emit sizeof(expr): resolve the expression's type then its size.
| expr | The expression whose type to measure. |
Convenience wrapper: MakeSizeofExpr(expr).
| Node * __builtin_ast_sizeof_type | ( | Type * | ty | ) |
Emit sizeof(ty) as a compile-time integer literal.
| ty | The type to measure. |
Convenience wrapper: MakeSizeofType(ty).
| Node * __builtin_ast_string_literal | ( | const char * | str | ) |
Build a string literal AST node.
| str | A NUL-terminated string. |
Convenience wrapper: MakeStringLiteral(str).
| const char * __builtin_ast_string_literal_value | ( | Node * | node | ) |
Return the text of a string literal node.
| node | A node, typically a macro or attribute argument. |
Convenience wrapper: StringLiteralValue(node).
| Type * __builtin_ast_struct_add_current_field | ( | const char * | name, |
| Type * | field_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.
| ty | The struct or union type to modify. |
| name | The field name. |
| field_type | The field's type. |
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).
| Member * __builtin_ast_struct_member_at | ( | Type * | struct_type, |
| int | index | ||
| ) |
Return the member at the given index.
| struct_type | The struct or union type to inspect. |
| index | Zero-based member index. |
Convenience wrapper: StructMemberAt(ty, index).
| int __builtin_ast_struct_member_count | ( | Type * | struct_type | ) |
Return the number of members of a struct or union type.
| struct_type | The struct or union type to inspect. |
Convenience wrapper: StructMemberCount(ty).
| Member * __builtin_ast_struct_member_find | ( | Type * | struct_type, |
| const char * | name | ||
| ) |
Look up a struct or union member by name.
| struct_type | The struct or union type to search. |
| name | The member name to look up. |
Convenience wrapper: StructMemberFind(ty, name).
| Node * __builtin_ast_subscript | ( | Node * | arr, |
| Node * | idx | ||
| ) |
Build an array subscript node: arr[idx], desugared as *(arr+idx).
| arr | The array (or pointer) expression. |
| idx | The index expression. |
Convenience wrapper: MakeSubscript(arr, idx).
| Node * __builtin_ast_switch | ( | Node * | cond | ) |
Build a switch statement node.
| cond | The expression to switch on. |
Convenience wrapper: MakeSwitch(cond).
| void __builtin_ast_switch_add_case | ( | Node * | switch_node, |
| Node * | value, | ||
| Node * | body | ||
| ) |
Append a case to a switch statement.
| switch_node | The switch node returned by __builtin_ast_switch. |
| value | The case value expression. |
| body | The body statement for this case. |
Convenience wrapper: SwitchAddCase(sw, value, body), or SwitchAddCase(value, body) inside WithSwitch(sw).
| void __builtin_ast_switch_add_current_case | ( | Node * | value, |
| Node * | body | ||
| ) |
| Node * __builtin_ast_switch_case_at | ( | Node * | sw, |
| int | index | ||
| ) |
Return a case label of a switch, in source order.
| sw | An NK_SWITCH node. |
| index | Zero-based case index. |
Convenience wrapper: SwitchCaseAt(sw, i).
| int __builtin_ast_switch_case_count | ( | Node * | sw | ) |
Return the number of case labels of a switch (excluding default).
| sw | An NK_SWITCH node. |
Convenience wrapper: SwitchCaseCount(sw).
| Node * __builtin_ast_switch_default | ( | Node * | sw | ) |
Return the default label of a switch.
| sw | An NK_SWITCH node. |
Convenience wrapper: SwitchDefault(sw).
| void __builtin_ast_switch_set_current_default | ( | Node * | body | ) |
| void __builtin_ast_switch_set_default | ( | Node * | switch_node, |
| Node * | body | ||
| ) |
Set the default case for a switch statement.
| switch_node | The switch node returned by __builtin_ast_switch. |
| body | The default-case body statement. |
Convenience wrapper: SwitchSetDefault(sw, body), or SwitchSetDefault(body) inside WithSwitch(sw).
| Token * __builtin_ast_synthetic_token | ( | const char * | label | ) |
Create an opaque synthetic source token for generated AST nodes.
| label | Short diagnostic label for the synthetic location. |
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).
| Token * __builtin_ast_token_from_node | ( | Node * | node | ) |
Return the opaque source token attached to a node.
| node | Node to inspect. |
Convenience wrapper: TokenFromNode(node).
| int __builtin_ast_type_align | ( | Type * | ty | ) |
Return _Alignof(ty) in bytes.
| ty | The type to inspect. |
Convenience wrapper: TypeAlign(ty).
| int __builtin_ast_type_array_len | ( | Type * | ty | ) |
Return the fixed length of an array type.
| ty | The array type to inspect. |
Convenience wrapper: TypeArrayLen(ty).
| Type * __builtin_ast_type_base | ( | Type * | ty | ) |
Return the element type of a pointer or array.
| ty | The pointer/array type to inspect. |
Convenience wrapper: TypeBase(ty).
| const char * __builtin_ast_type_c_name | ( | Type * | ty | ) |
Return a valid C identifier fragment naming ty.
| ty | The type to inspect. |
Convenience wrapper: TypeCName(ty). Intended for naming generated functions, e.g. sum_<T> from GenerateSum(elem_type).
| bool __builtin_ast_type_exists | ( | const char * | name | ) |
Check whether a type is currently in scope by name.
| name | The type name to look up. |
Convenience wrapper: TypeExists(name).
| bool __builtin_ast_type_is_const | ( | Type * | ty | ) |
Test whether a type is const-qualified.
| ty | The type to inspect. |
Convenience wrapper: TypeIsConst(ty).
| bool __builtin_ast_type_is_unsigned | ( | Type * | ty | ) |
Test whether an integer type is unsigned.
| ty | The type to inspect. |
Convenience wrapper: TypeIsUnsigned(ty).
| bool __builtin_ast_type_is_variadic | ( | Type * | ty | ) |
Test whether a function type is variadic.
| ty | The type to inspect. |
Convenience wrapper: TypeIsVariadic(ty).
| TypeKind __builtin_ast_type_kind | ( | Type * | ty | ) |
Return the TypeKind tag of a type.
| ty | The type to inspect. |
Convenience wrapper: GetTypeKind(ty).
| const char * __builtin_ast_type_name | ( | Type * | ty | ) |
Return the user-visible name of a type, if any.
| ty | The type to inspect. |
Convenience wrapper: TypeName(ty).
| Type * __builtin_ast_type_param_at | ( | Type * | ty, |
| int | index | ||
| ) |
Return the type of the parameter at the given index.
| ty | The function type to inspect. |
| index | Zero-based parameter index. |
Convenience wrapper: TypeParamAt(ty, index).
| int __builtin_ast_type_param_count | ( | Type * | ty | ) |
Return the number of declared parameters of a function type.
| ty | The function type to inspect. |
Convenience wrapper: TypeParamCount(ty).
| Type * __builtin_ast_type_return_type | ( | Type * | ty | ) |
Return the return type of a function type.
| ty | The function type to inspect. |
Convenience wrapper: TypeReturnType(ty).
| int __builtin_ast_type_size | ( | Type * | ty | ) |
Return sizeof(ty) in bytes.
| ty | The type to inspect. |
Convenience wrapper: TypeSize(ty).
| Node * __builtin_ast_unary | ( | NodeKind | op, |
| Node * | operand | ||
| ) |
Build a unary operation AST node.
| op | The operator kind (NK_NEG, NK_DEREF, ...). |
| operand | The operand expression. |
Convenience wrapper: MakeUnary(op, operand).
| Node * __builtin_ast_var_ref | ( | const char * | name | ) |
Build a variable reference AST node.
| name | The variable name. |
Convenience wrapper: MakeVarRef(name).
| Node * __builtin_ast_vararg_at | ( | int | index | ) |
Return an inline macro's variadic AST argument by zero-based index.
| index | Zero-based variadic argument index. |
Emits a compile-time error if index is out of range or the active macro call is a global-generation string macro.
| int __builtin_ast_vararg_count | ( | void | ) |
Return the number of variadic arguments for the active macro call.
| const char * __builtin_ast_vararg_str_at | ( | int | index | ) |
Return a global-generation macro's stringified variadic argument.
| index | Zero-based variadic argument index. |
Emits a compile-time error if index is out of range or the active macro call is an inline AST macro.
| Node ** __builtin_ast_varargs_as_array | ( | void | ) |
Return an inline macro's variadic AST arguments as an array.
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.
| Node * __builtin_ast_while | ( | Node * | cond, |
| Node * | body | ||
| ) |
Create a while loop node.
| cond | The loop condition expression. |
| body | The loop body statement, or NULL to attach one later with LoopSetBody (typically inside a WithLoop(loop) block). |
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).
| int __builtin_attr_target_kind | ( | AttrTarget * | target | ) |
Return the kind of declaration decorated by a custom attribute.
| Member * __builtin_attr_target_member | ( | AttrTarget * | target | ) |
Return the attributed member of an ATTR_TARGET_MEMBER target, else NULL.
| const char * __builtin_attr_target_name | ( | AttrTarget * | target | ) |
Return the decorated declaration's source name, when available.
| Obj * __builtin_attr_target_obj | ( | AttrTarget * | target | ) |
Return the decorated function or global object, or NULL for type targets.
| 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.
| Token * __builtin_attr_target_token | ( | AttrTarget * | target | ) |
Return a source token for the decorated declaration.
| Type * __builtin_attr_target_type | ( | AttrTarget * | target | ) |
Return the decorated declaration's type.
| void __builtin_dump_ast_gen | ( | Node * | node | ) |
Print __builtin_ast_*() builder calls that would reconstruct the node.
| node | The 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).
| const char * __builtin_dump_ast_gen_to_string | ( | Node * | node | ) |
Render the __builtin_ast_*() builder call sequence to a string.
| node | The root node. |
Convenience wrapper: DumpAstGenToString(node).
| void __builtin_dump_tree | ( | Node * | node | ) |
Print a human-readable tree representation of a node to stdout.
| node | The root node to print. |
Reuses the compiler's internal cc_dump_ast text renderer. Convenience wrapper: DumpTree(node).
| const char * __builtin_dump_tree_to_string | ( | Node * | node | ) |
Render the tree representation to a heap-allocated string.
| node | The root node. |
Convenience wrapper: DumpTreeToString(node).
| void __builtin_emit_directive | ( | const char * | line | ) |
Emit one raw preprocessor directive line into generated output.
| line | Complete directive text, for example "#ifdef _WIN32". |
Convenience wrapper: EmitDirective(line).
| 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).
| 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).
| 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).
| void __builtin_generate_sum | ( | Type * | elem_ty | ) |
Publish T sum_T(T *arr, size_t n) summing all elements.
Convenience wrapper: GenerateSum(elem_type).
| const char * __builtin_gensym | ( | const char * | prefix | ) |
Generate a unique identifier string for macro-created symbols.
| prefix | Prefix for the generated name. |
Convenience wrapper: Gensym(prefix).
| double __builtin_get_comptime_float | ( | const char * | name | ) |
Read a float/double-typed #pragma comptime variable's value at compile time.
| name | The comptime variable's name. |
Convenience wrapper: GetComptimeFloat(name).
| int64_t __builtin_get_comptime_int | ( | const char * | name | ) |
Read an integer-typed #pragma comptime variable's value at compile time.
| name | The comptime variable's name. |
Convenience wrapper: GetComptimeInt(name).
| 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.
| var_name | The comptime struct variable's name. |
| field | The field name to look up. |
Convenience wrapper: GetComptimeMember(var_name, field).
| Node * __builtin_get_comptime_ptr | ( | const char * | name | ) |
Return the address of a comptime variable as a generated-code AST pointer node.
| name | The comptime variable's name. |
Convenience wrapper: GetComptimePtr(name).
| Node * __builtin_get_comptime_var | ( | const char * | name | ) |
Read a comptime scalar variable as an AST literal node.
| name | The comptime variable's name. |
Convenience wrapper: GetComptimeVar(name).
| Node * __builtin_get_constexpr_value | ( | const char * | name | ) |
Read the evaluated initializer of a global constexpr variable as an AST literal node.
| name | The constexpr variable's name. |
Errors at compile time if name does not refer to a visible constexpr variable. Convenience wrapper: GetConstexprValue(name).
| void __builtin_macro_error_at | ( | Node * | node, |
| const char * | fmt, | ||
| ... | |||
| ) |
Emit a compiler error pointing at the source location of a node.
| node | A node whose tok field provides file/line/col. May be NULL (falls back to a location-less error). |
| fmt | printf-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, ...).
| void void __builtin_macro_warning_at | ( | Node * | node, |
| const char * | fmt, | ||
| ... | |||
| ) |
Emit a compiler warning pointing at the source location of a node.
| node | A node whose tok field provides file/line/col. May be NULL. |
| fmt | printf-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, ...).
| 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).
| node | The node to fully expand. |
| 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).
| node | The node to (possibly) expand. |
| 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.
| nodes | Array of Node* to link together. Linking stops at the first NULL element or at count, whichever comes first. |
| count | Number of elements in the array. |
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).
| 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.
| tmpl | A 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 $$.$@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.
| ... | Node* arguments corresponding to the splice points. |
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, ...).
| Node * __builtin_quote_lazy | ( | const char * | tmpl, |
| ... | |||
| ) |
Deferred (unparsed) quasi-quote: captures a template and its splice arguments without parsing it.
| tmpl | A 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. |
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, ...).
| Node * __builtin_quote_lazy_n | ( | const char * | tmpl, |
| Node ** | nodes, | ||
| int | count | ||
| ) |
Array-form deferred quasi-quote; see __builtin_quote_lazy.
| tmpl | Template string with $N / $@N splice points. |
| nodes | Array of Node* splice arguments. |
| count | Length of the nodes array. If any $K in the template exceeds count, a compile-time error is emitted at this call. |
ND_QUOTE_LAZY node; see __builtin_quote_lazy.Convenience wrapper: QuoteLazyN(tmpl, nodes, count).
| 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.
| tmpl | A C expression or statement as a string literal with $N / $@N splice points. |
| nodes | Array of Node* splice arguments. |
| count | Length of the nodes array. If any $K in the template exceeds count, a compile-time error is emitted. |
Convenience wrapper: QuoteN(tmpl, nodes, count).
| 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("...")).
| struct __CCCC_TAG | ( | EnumConstant | ) |
Opaque enum constant descriptor, returned by EnumAt / EnumFind and inspected with EnumConstantName / EnumConstantValue.
| struct __CCCC_TAG | ( | Member | ) |
Opaque struct/union member descriptor, returned by StructMemberAt / StructMemberFind and inspected with the Member* family of macros.
| 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.
| struct __CCCC_TAG | ( | Obj | ) |
Opaque global symbol (a function or global variable). Created by MakeFunction / GlobalVar, or looked up with FindGlobal / GlobalAt.
| struct __CCCC_TAG | ( | Token | ) |
Opaque source-location handle attached to AST nodes for diagnostics. Obtained via CurrentToken / SyntheticToken / TokenFromNode and attached with SetToken.
| 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.
| 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.