85#ifndef CCCC_REFLECTION_H
86#define CCCC_REFLECTION_H
103#define __CCCC_TAG(n) __cccc_##n
109typedef struct __CCCC_TAG(VirtualMachine) VirtualMachine;
114typedef struct __CCCC_TAG(Type) Type;
120typedef struct __CCCC_TAG(Node) Node;
125typedef struct __CCCC_TAG(Obj) Obj;
130typedef struct __CCCC_TAG(Member) Member;
134typedef struct __CCCC_TAG(EnumConstant) EnumConstant;
139typedef struct __CCCC_TAG(Token) Token;
145typedef struct __CCCC_TAG(AttrTarget) AttrTarget;
147#ifndef CCCC_REFLECTION_PROTOTYPES_ONLY
420 __attribute__((format(printf, 2, 3)));
430 __attribute__((format(printf, 2, 3)));
2144#define Quote(tmpl, ...) __builtin_quote(tmpl, ##__VA_ARGS__)
2153#define QuoteN(tmpl, nodes, count) __builtin_quote_n(tmpl, nodes, count)
2167#define QuoteLazy(tmpl, ...) __builtin_quote_lazy(tmpl, ##__VA_ARGS__)
2175#define QuoteLazyN(tmpl, nodes, count) \
2176 __builtin_quote_lazy_n(tmpl, nodes, count)
2184#define NodeList(nodes, count) __builtin_node_list(nodes, count)
2191#define MacroErrorAt(node, ...) __builtin_macro_error_at(node, __VA_ARGS__)
2197#define MacroWarningAt(node, ...) __builtin_macro_warning_at(node, __VA_ARGS__)
2203#define DumpTree(node) __builtin_dump_tree(node)
2207#define DumpTreeToString(node) __builtin_dump_tree_to_string(node)
2212#define DumpAstGen(node) __builtin_dump_ast_gen(node)
2217#define DumpAstGenToString(node) __builtin_dump_ast_gen_to_string(node)
2221#define Gensym(prefix) __builtin_gensym(prefix)
2225#define MacroExpand1(node) __builtin_macroexpand_1(node)
2230#define MacroExpand(node) __builtin_macroexpand(node)
2233#define VarargCount() __builtin_ast_vararg_count()
2237#define VarargAt(i) __builtin_ast_vararg_at(i)
2241#define VarargAsArray() __builtin_ast_varargs_as_array()
2246#define VarargStrAt(i) __builtin_ast_vararg_str_at(i)
2248#define __builtin_dispatch_2(_1, _2, which, ...) which(_1, _2)
2249#define __builtin_dispatch_3(_1, _2, _3, which, ...) which(_1, _2, _3)
2253#define CurrentToken() __builtin_ast_current_token()
2257#define SyntheticToken(label) __builtin_ast_synthetic_token(label)
2261#define TokenFromNode(node) __builtin_ast_token_from_node(node)
2267#define SetToken(node, tok) __builtin_ast_set_token(node, tok)
2272#define CopyLocation(dst, src) __builtin_ast_copy_location(dst, src)
2277#define CopyNode(n) __builtin_ast_copy_node(n)
2282#define FindType(name) __builtin_ast_find_type(name)
2286#define TypeExists(name) __builtin_ast_type_exists(name)
2292#define GetType(name) __builtin_ast_get_type(name)
2298#define GetTypeKind(ty) __builtin_ast_type_kind(ty)
2302#define TypeSize(ty) __builtin_ast_type_size(ty)
2306#define TypeAlign(ty) __builtin_ast_type_align(ty)
2310#define TypeIsUnsigned(ty) __builtin_ast_type_is_unsigned(ty)
2314#define TypeIsConst(ty) __builtin_ast_type_is_const(ty)
2318#define TypeBase(ty) __builtin_ast_type_base(ty)
2322#define TypeArrayLen(ty) __builtin_ast_type_array_len(ty)
2326#define TypeReturnType(ty) __builtin_ast_type_return_type(ty)
2330#define TypeParamCount(ty) __builtin_ast_type_param_count(ty)
2335#define TypeParamAt(ty, i) __builtin_ast_type_param_at(ty, i)
2339#define TypeIsVariadic(ty) __builtin_ast_type_is_variadic(ty)
2343#define TypeName(ty) __builtin_ast_type_name(ty)
2348#define TypeCName(ty) __builtin_ast_type_c_name(ty)
2353#define MakeIntLiteral(val) __builtin_ast_int_literal(val)
2357#define MakeFloatLiteral(val) __builtin_ast_float_literal(val)
2361#define MakeStringLiteral(str) __builtin_ast_string_literal(str)
2365#define StringLiteralValue(node) __builtin_ast_string_literal_value(node)
2370#define ConstIntValue(node, out) __builtin_ast_const_int_value(node, out)
2376#define ConstUIntValue(node, out) __builtin_ast_const_uint_value(node, out)
2380#define MakeVarRef(name) __builtin_ast_var_ref(name)
2385#define MakeParamRef(fn, name) __builtin_ast_param_ref(fn, name)
2392#define MakeBinary(op, l, r) __builtin_ast_binary(op, l, r)
2397#define MakeUnary(op, operand) __builtin_ast_unary(op, operand)
2402#define MakeCast(expr, ty) __builtin_ast_cast(expr, ty)
2412#define MakeCond(c, t, e) __builtin_ast_cond(c, t, e)
2416#define MakeNull() __builtin_ast_null()
2421#define MakeSizeofType(ty) __builtin_ast_sizeof_type(ty)
2425#define MakeAlignofType(ty) __builtin_ast_alignof_type(ty)
2431#define MakeSizeofExpr(expr) __builtin_ast_sizeof_expr(expr)
2438#define MakeSubscript(arr, idx) __builtin_ast_subscript(arr, idx)
2444#define MakeComma(lhs, rhs) __builtin_ast_comma(lhs, rhs)
2449#define MakeReturn(expr) __builtin_ast_return(expr)
2454#define MakeBlock(stmts, count) __builtin_ast_block(stmts, count)
2455#define __builtin_block_add_stmt_1(stmt, _ignored) \
2456 __builtin_ast_block_add_current_stmt(stmt)
2457#define __builtin_block_add_stmt_2(block, stmt) \
2458 __builtin_ast_block_add_stmt(block, stmt)
2464#define BlockAddStmt(...) \
2465 __builtin_dispatch_2(__VA_ARGS__, __builtin_block_add_stmt_2, \
2466 __builtin_block_add_stmt_1)
2472#define MakeIf(c, t, e) __builtin_ast_if(c, t, e)
2478#define MakeSwitch(cond) __builtin_ast_switch(cond)
2479#define __builtin_switch_add_case_2(v, b, _ignored) \
2480 __builtin_ast_switch_add_current_case(v, b)
2481#define __builtin_switch_add_case_3(sw, v, b) \
2482 __builtin_ast_switch_add_case(sw, v, b)
2488#define SwitchAddCase(...) \
2489 __builtin_dispatch_3(__VA_ARGS__, __builtin_switch_add_case_3, \
2490 __builtin_switch_add_case_2)
2491#define __builtin_switch_set_default_1(b, _ignored) \
2492 __builtin_ast_switch_set_current_default(b)
2493#define __builtin_switch_set_default_2(sw, b) \
2494 __builtin_ast_switch_set_default(sw, b)
2500#define SwitchSetDefault(...) \
2501 __builtin_dispatch_2(__VA_ARGS__, __builtin_switch_set_default_2, \
2502 __builtin_switch_set_default_1)
2506#define MakeExprStmt(expr) __builtin_ast_expr_stmt(expr)
2513#define MakeLocalVar(name, ty) __builtin_ast_local_var(name, ty)
2520#define MakeLocalVarUnique(ty) __builtin_ast_local_var_unique(ty)
2525#define MakeAssign(target, value) __builtin_ast_assign(target, value)
2532#define MakeMember(obj, name) __builtin_ast_member(obj, name)
2539#define MakeFuncCall(callee, args, n) __builtin_ast_funcall(callee, args, n)
2548#define Memcpy(dst, src, n) \
2549 __builtin_ast_funcall(__builtin_ast_var_ref("memcpy"), \
2550 (Node *[]){(dst), (src), (n)}, 3)
2555 __builtin_ast_funcall(__builtin_ast_var_ref("strlen"), (Node *[]){(s)}, 1)
2560#define Strcmp(a, b) \
2561 __builtin_ast_funcall(__builtin_ast_var_ref("strcmp"), \
2562 (Node *[]){(a), (b)}, 2)
2567#define MakeWhile(cond, body) __builtin_ast_while(cond, body)
2574#define MakeFor(init, cond, inc, body) __builtin_ast_for(init, cond, inc, body)
2579#define MakeDoWhile(body, cond) __builtin_ast_do_while(body, cond)
2584#define LoopSetBody(loop, body) __builtin_ast_loop_set_body(loop, body)
2590#define WithLoop(loop) \
2591 for (int _cccc_loop_ctx_ = (__builtin_ast_push_loop((loop)), 1); \
2592 _cccc_loop_ctx_; _cccc_loop_ctx_ = (__builtin_ast_pop_loop(), 0))
2597#define MakePointer(base) __builtin_ast_make_pointer(base)
2602#define MakeArray(base, len) __builtin_ast_make_array(base, len)
2608#define MakeFuncPtrType(ret, params, n) \
2609 __builtin_ast_make_func_ptr_type(ret, params, n)
2615#define MakeConst(ty) __builtin_ast_make_const(ty)
2619#define MakeVolatile(ty) __builtin_ast_make_volatile(ty)
2624#define EnumCount(ty) __builtin_ast_enum_count(ty)
2629#define EnumAt(ty, i) __builtin_ast_enum_at(ty, i)
2634#define EnumFind(ty, name) __builtin_ast_enum_find(ty, name)
2638#define EnumConstantName(ec) __builtin_ast_enum_constant_name(ec)
2642#define EnumConstantValue(ec) __builtin_ast_enum_constant_value(ec)
2646#define EnumName(ty) __builtin_ast_enum_name(ty)
2650#define EnumValueCount(ty) __builtin_ast_enum_value_count(ty)
2655#define EnumValueName(ty, i) __builtin_ast_enum_value_name(ty, i)
2660#define EnumValue(ty, i) __builtin_ast_enum_value(ty, i)
2668#define EnumToString(ty, expr) __builtin_ast_enum_to_string_switch(ty, expr)
2676#define EnumFromString(ty, expr) __builtin_ast_enum_from_string_chain(ty, expr)
2681#define StructMemberCount(ty) __builtin_ast_struct_member_count(ty)
2686#define StructMemberAt(ty, i) __builtin_ast_struct_member_at(ty, i)
2691#define StructMemberFind(ty, name) __builtin_ast_struct_member_find(ty, name)
2695#define MemberName(m) __builtin_ast_member_name(m)
2699#define MemberType(m) __builtin_ast_member_type(m)
2703#define MemberOffset(m) __builtin_ast_member_offset(m)
2707#define MemberIsBitfield(m) __builtin_ast_member_is_bitfield(m)
2711#define MemberBitfieldWidth(m) __builtin_ast_member_bitfield_width(m)
2719#define __builtin_foreach_member_body(type, varname, body, uid) \
2721 Type *__builtin_fem_ty_##uid = (type); \
2722 int __builtin_fem_n_##uid = StructMemberCount(__builtin_fem_ty_##uid); \
2723 for (int __builtin_fem_i_##uid = 0; \
2724 __builtin_fem_i_##uid < __builtin_fem_n_##uid; \
2725 __builtin_fem_i_##uid++) { \
2727 StructMemberAt(__builtin_fem_ty_##uid, __builtin_fem_i_##uid); \
2731#define __builtin_foreach_member_uid(type, varname, body, uid) \
2732 __builtin_foreach_member_body(type, varname, body, uid)
2742#define ForeachMember(type, varname, body) \
2743 __builtin_foreach_member_uid(type, varname, body, __COUNTER__)
2750#define OffsetofChain(type, ...) \
2751 MakeIntLiteral(__builtin_ast_offsetof_chain( \
2752 type, (const char *[]){__VA_ARGS__}, \
2753 (int)(sizeof((const char *[]){__VA_ARGS__}) / sizeof(const char *))))
2758#define FindGlobal(name) __builtin_ast_find_global(name)
2761#define GlobalCount() __builtin_ast_global_count()
2765#define GlobalAt(i) __builtin_ast_global_at(i)
2769#define ObjName(obj) __builtin_ast_obj_name(obj)
2773#define ObjType(obj) __builtin_ast_obj_type(obj)
2777#define ObjIsFunction(obj) __builtin_ast_obj_is_function(obj)
2781#define ObjIsDefinition(obj) __builtin_ast_obj_is_definition(obj)
2785#define ObjIsStatic(obj) __builtin_ast_obj_is_static(obj)
2789#define FnBody(fn) __builtin_ast_function_body(fn)
2793#define FnParamCount(fn) __builtin_ast_function_param_count(fn)
2798#define FnParamAt(fn, i) __builtin_ast_function_param_at(fn, i)
2802#define FnLocalCount(fn) __builtin_ast_function_local_count(fn)
2808#define FnLocalAt(fn, i) __builtin_ast_function_local_at(fn, i)
2812#define ObjNext(obj) __builtin_ast_obj_next(obj)
2816#define GetNodeKind(node) __builtin_ast_node_kind(node)
2820#define GetNodeType(node) __builtin_ast_node_type(node)
2824#define NodeNext(node) __builtin_ast_node_next(node)
2828#define NodeLhs(node) __builtin_ast_node_lhs(node)
2832#define NodeRhs(node) __builtin_ast_node_rhs(node)
2836#define NodeBody(node) __builtin_ast_node_body(node)
2840#define NodeCond(node) __builtin_ast_node_cond(node)
2845#define NodeThen(node) __builtin_ast_node_then(node)
2849#define NodeElse(node) __builtin_ast_node_else(node)
2853#define NodeInit(node) __builtin_ast_node_init(node)
2857#define NodeInc(node) __builtin_ast_node_inc(node)
2861#define BlockCount(block) __builtin_ast_block_count(block)
2866#define BlockAt(block, i) __builtin_ast_block_at(block, i)
2870#define CallCallee(call) __builtin_ast_call_callee(call)
2874#define CallArgCount(call) __builtin_ast_call_arg_count(call)
2879#define CallArgAt(call, i) __builtin_ast_call_arg_at(call, i)
2883#define NodeIntValue(node) __builtin_ast_node_int_value(node)
2887#define NodeFloatValue(node) __builtin_ast_node_float_value(node)
2891#define NodeVarObj(node) __builtin_ast_node_var_obj(node)
2895#define NodeMember(node) __builtin_ast_node_member(node)
2899#define SwitchCaseCount(sw) __builtin_ast_switch_case_count(sw)
2904#define SwitchCaseAt(sw, i) __builtin_ast_switch_case_at(sw, i)
2908#define SwitchDefault(sw) __builtin_ast_switch_default(sw)
2912#define CaseBegin(node) __builtin_ast_case_begin(node)
2917#define CaseEnd(node) __builtin_ast_case_end(node)
2921#define CaseBody(node) __builtin_ast_case_body(node)
2925#define MacroCallName(node) __builtin_ast_macro_call_name(node)
2929#define MacroCallArgCount(node) __builtin_ast_macro_call_arg_count(node)
2934#define MacroCallArgAt(node, i) __builtin_ast_macro_call_arg_at(node, i)
2938#define StripImplicit(node) __builtin_ast_node_strip_implicit(node)
2942#define LabelName(node) __builtin_ast_label_name(node)
2946#define GotoJumpKind(node) __builtin_ast_goto_jump_kind(node)
2950#define AsmTemplate(node) __builtin_ast_asm_template(node)
2954#define AsmOutputCount(node) __builtin_ast_asm_output_count(node)
2958#define AsmInputCount(node) __builtin_ast_asm_input_count(node)
2963#define AsmOperandConstraint(node, i) \
2964 __builtin_ast_asm_operand_constraint(node, i)
2969#define AsmOperandName(node, i) __builtin_ast_asm_operand_name(node, i)
2974#define AsmOperandExpr(node, i) __builtin_ast_asm_operand_expr(node, i)
2978#define AsmClobberCount(node) __builtin_ast_asm_clobber_count(node)
2983#define AsmClobberAt(node, i) __builtin_ast_asm_clobber_at(node, i)
2987#define AsmIsVolatile(node) __builtin_ast_asm_is_volatile(node)
2991#define AsmIsGoto(node) __builtin_ast_asm_is_goto(node)
2995#define AsmGotoLabelCount(node) __builtin_ast_asm_goto_label_count(node)
3000#define AsmGotoLabelAt(node, i) __builtin_ast_asm_goto_label_at(node, i)
3005#define AtomicOrder(node) __builtin_ast_atomic_order(node)
3009#define AtomicFailOrder(node) __builtin_ast_atomic_fail_order(node)
3013#define AtomicIsWeak(node) __builtin_ast_atomic_is_weak(node)
3017#define CasAddr(node) __builtin_ast_cas_addr(node)
3021#define CasExpected(node) __builtin_ast_cas_expected(node)
3025#define CasDesired(node) __builtin_ast_cas_desired(node)
3029#define FenceIsSignal(node) __builtin_ast_fence_is_signal(node)
3033#define BitopOp(node) __builtin_ast_bitop_op(node)
3037#define BitopWidth(node) __builtin_ast_bitop_width(node)
3041#define OverflowOp(node) __builtin_ast_overflow_op(node)
3045#define OverflowResultPtr(node) __builtin_ast_overflow_result_ptr(node)
3049#define GetAttrTargetKind(target) __builtin_attr_target_kind(target)
3053#define AttrTargetName(target) __builtin_attr_target_name(target)
3057#define AttrTargetType(target) __builtin_attr_target_type(target)
3062#define AttrTargetObj(target) __builtin_attr_target_obj(target)
3066#define AttrTargetToken(target) __builtin_attr_target_token(target)
3070#define AttrTargetMember(target) __builtin_attr_target_member(target)
3075#define AttrTargetOwner(target) __builtin_attr_target_owner(target)
3079#define AttrTargetParam(target) __builtin_attr_target_param(target)
3084#define AttrTargetParamIndex(target) __builtin_attr_target_param_index(target)
3088#define MemberHasAttr(m, name) __builtin_ast_member_has_attr(m, name)
3092#define MemberAttrArgCount(m, name) __builtin_ast_member_attr_arg_count(m, name)
3096#define MemberAttrArg(m, name, i) __builtin_ast_member_attr_arg(m, name, i)
3100#define MemberAttrCount(m) __builtin_ast_member_attr_count(m)
3104#define MemberAttrNameAt(m, i) __builtin_ast_member_attr_name_at(m, i)
3108#define MemberAttrArgCountAt(m, i) __builtin_ast_member_attr_arg_count_at(m, i)
3112#define MemberAttrArgAt(m, i, j) __builtin_ast_member_attr_arg_at(m, i, j)
3117#define ParamHasAttr(p, name) __builtin_ast_param_has_attr(p, name)
3121#define ParamAttrArgCount(p, name) __builtin_ast_param_attr_arg_count(p, name)
3126#define ParamAttrArg(p, name, i) __builtin_ast_param_attr_arg(p, name, i)
3130#define ParamAttrCount(p) __builtin_ast_param_attr_count(p)
3134#define ParamAttrNameAt(p, i) __builtin_ast_param_attr_name_at(p, i)
3138#define ParamAttrArgCountAt(p, i) __builtin_ast_param_attr_arg_count_at(p, i)
3142#define ParamAttrArgAt(p, i, j) __builtin_ast_param_attr_arg_at(p, i, j)
3148#define MakeFunction(name, ret_type) __builtin_ast_function(name, ret_type)
3154#define PublishNode(decl) \
3156 Obj *: __builtin_ast_publish, \
3157 Type *: __builtin_ast_publish_type)((decl), 0)
3162#define PublishNodeAt(decl, tok) \
3164 Obj *: __builtin_ast_publish, \
3165 Type *: __builtin_ast_publish_type)((decl), (tok))
3169#define EmitDirective(line) __builtin_emit_directive(line)
3176#define FunctionAddParam(fn, name, type) \
3177 __builtin_ast_function_add_param(fn, name, type)
3189#define FunctionSetBody(fn, body) __builtin_ast_function_set_body(fn, body)
3194#define FunctionSetStatic(fn, is_static) \
3195 __builtin_ast_function_set_static(fn, is_static)
3200#define FunctionSetInline(fn, is_inline) \
3201 __builtin_ast_function_set_inline(fn, is_inline)
3206#define FunctionSetVariadic(fn, is_variadic) \
3207 __builtin_ast_function_set_variadic(fn, is_variadic)
3219#define FunctionPrototype(name, ret) __builtin_ast_function_prototype(name, ret)
3230#define AddAttribute(fn, text) __builtin_ast_add_attribute(fn, text)
3234#define MarkAsTest(fn) AddAttribute(fn, "cccc::test")
3238#define MarkAsBuild(fn) AddAttribute(fn, "cccc::build")
3243#define MarkAsBuildTarget(fn, kind) \
3244 __builtin_ast_add_build_target_attr(fn, kind)
3260#define MakeStruct(name) __builtin_ast_make_struct(name)
3264#define MakeUnion(name) __builtin_ast_make_union(name)
3265#define __builtin_struct_add_field_2(name, field_type, _ignored) \
3266 __builtin_ast_struct_add_current_field(name, field_type)
3267#define __builtin_struct_add_field_3(ty, name, field_type) \
3268 __builtin_ast_struct_add_field(ty, name, field_type)
3275#define StructAddField(...) \
3276 __builtin_dispatch_3(__VA_ARGS__, __builtin_struct_add_field_3, \
3277 __builtin_struct_add_field_2)
3282#define MakeEnum(name) __builtin_ast_make_enum(name)
3283#define __builtin_enum_add_constant_2(name, value, _ignored) \
3284 __builtin_ast_enum_add_current_constant(name, value)
3285#define __builtin_enum_add_constant_3(ty, name, value) \
3286 __builtin_ast_enum_add_constant(ty, name, value)
3292#define EnumAddConstant(...) \
3293 __builtin_dispatch_3(__VA_ARGS__, __builtin_enum_add_constant_3, \
3294 __builtin_enum_add_constant_2)
3299#define MakeTypedef(name, underlying) \
3300 __builtin_ast_make_typedef(name, underlying)
3344#define GetComptimeInt(name) __builtin_get_comptime_int(name)
3349#define GetComptimeFloat(name) __builtin_get_comptime_float(name)
3353#define GetComptimeVar(name) __builtin_get_comptime_var(name)
3358#define GetComptimePtr(name) __builtin_get_comptime_ptr(name)
3364#define GetComptimeMember(var, field) __builtin_get_comptime_member(var, field)
3384#define GetConstexprValue(name) __builtin_get_constexpr_value(name)
3418#define CompoundLiteral(ty, ...) \
3419 __builtin_ast_compound_literal( \
3420 ty, (Node *[]){__VA_ARGS__}, \
3421 (int)(sizeof((Node *[]){__VA_ARGS__}) / sizeof(Node *)))
3428#define InitArray(elem_ty, ...) \
3429 __builtin_ast_init_array( \
3430 elem_ty, (Node *[]){__VA_ARGS__}, \
3431 (int)(sizeof((Node *[]){__VA_ARGS__}) / sizeof(Node *)))
3442#define InitStruct(ty, fields, values, n) \
3443 __builtin_ast_init_struct(ty, fields, values, n)
3478#define Serialize(ty, expr, buf) __builtin_ast_serialize(ty, expr, buf)
3485#define Deserialize(ty, buf) __builtin_ast_deserialize(ty, buf)
3492#define GlobalVar(name, ty) __builtin_ast_global_var(name, ty)
3498#define GlobalVarSetInitData(var, data, len) \
3499 __builtin_ast_global_var_set_init_data(var, data, len)
3504#define GlobalVarSetStatic(var, is_static) \
3505 __builtin_ast_global_var_set_static(var, is_static)
3522 for (int _cccc_fn_ctx_ = (__builtin_ast_push_fn((fn)), 1); _cccc_fn_ctx_; \
3523 _cccc_fn_ctx_ = (__builtin_ast_pop_fn(), 0))
3531#define WithBlock(block) \
3532 for (int _cccc_block_ctx_ = (__builtin_ast_push_block((block)), 1); \
3533 _cccc_block_ctx_; _cccc_block_ctx_ = (__builtin_ast_pop_block(), 0))
3541#define WithStruct(ty) \
3542 for (int _cccc_struct_ctx_ = (__builtin_ast_push_struct((ty)), 1); \
3543 _cccc_struct_ctx_; \
3544 _cccc_struct_ctx_ = (__builtin_ast_pop_struct(), 0))
3552#define WithSwitch(sw) \
3553 for (int _cccc_switch_ctx_ = (__builtin_ast_push_switch((sw)), 1); \
3554 _cccc_switch_ctx_; \
3555 _cccc_switch_ctx_ = (__builtin_ast_pop_switch(), 0))
3563#define WithEnum(ty) \
3564 for (int _cccc_enum_ctx_ = (__builtin_ast_push_enum((ty)), 1); \
3565 _cccc_enum_ctx_; _cccc_enum_ctx_ = (__builtin_ast_pop_enum(), 0))
3602#define GenerateSum(elem_type) __builtin_generate_sum(elem_type)
3607#define GenerateMap(elem_type) __builtin_generate_map(elem_type)
3612#define GenerateReduce(elem_type) __builtin_generate_reduce(elem_type)
3617#define GenerateFilter(elem_type) __builtin_generate_filter(elem_type)
Node * __builtin_ast_sizeof_expr(Node *expr)
Emit sizeof(expr): resolve the expression's type then its size.
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 array...
Node * __builtin_ast_copy_node(Node *n)
Deep-copy an expression or statement tree.
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 mat...
Node * __builtin_ast_switch_default(Node *sw)
Return the default label of a switch.
int __builtin_ast_struct_member_count(Type *struct_type)
Return the number of members of a struct or union type.
Node * __builtin_ast_node_lhs(Node *node)
Return the left operand (or sole operand) of a node.
bool __builtin_ast_type_is_unsigned(Type *ty)
Test whether an integer type is unsigned.
AstBitop
The operation of an NK_BITOP node, returned by BitopOp(node).
Definition reflection.h:255
@ AST_BITOP_BSWAP
Definition reflection.h:261
@ AST_BITOP_CTZ
Definition reflection.h:257
@ AST_BITOP_POPCOUNT
Definition reflection.h:258
@ AST_BITOP_PARITY
Definition reflection.h:259
@ AST_BITOP_FFS
Definition reflection.h:260
@ AST_BITOP_CLZ
Definition reflection.h:256
Type * __builtin_ast_obj_type(Obj *obj)
Return the type of a global object.
Type * __builtin_attr_target_type(AttrTarget *target)
Return the decorated declaration's type.
Token * __builtin_attr_target_token(AttrTarget *target)
Return a source token for the decorated declaration.
Node * __builtin_ast_string_literal(const char *str)
Build a string literal AST node.
int __builtin_ast_function_param_count(Obj *fn)
Return the number of parameters of a function definition.
bool __builtin_ast_obj_is_function(Obj *obj)
Test whether a global object is a function.
Member * __builtin_ast_struct_member_find(Type *struct_type, const char *name)
Look up a struct or union member by name.
void __builtin_ast_push_fn(Obj *fn)
Establish fn as the "function currently being built" so that Quote("return x;") applies the correct i...
Type * __builtin_ast_make_typedef(const char *name, Type *underlying)
Register a typedef alias for a type and expose it in scope.
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.
Token * __builtin_ast_current_token(void)
Return the token for the macro invocation currently being executed.
void __builtin_ast_global_var_set_static(Obj *var, bool is_static)
Set the static (internal linkage) flag on a generated global.
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_expr_stmt(Node *expr)
Build an expression statement node.
double __builtin_get_comptime_float(const char *name)
Read a float/double-typed #pragma comptime variable's value at compile time.
Type * __builtin_ast_make_volatile(Type *ty)
Return a volatile-qualified copy of ty.
const char * __builtin_ast_vararg_str_at(int index)
Return a global-generation macro's stringified variadic argument.
Type * __builtin_ast_make_struct(const char *name)
Create and expose a new named struct type.
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.
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 a...
int __builtin_ast_overflow_op(Node *node)
Return the operation of an NK_OVERFLOW_ARITH.
bool __builtin_ast_const_uint_value(Node *node, uint64_t *out)
Evaluate an unsigned integer constant expression node.
Node * __builtin_ast_sizeof_type(Type *ty)
Emit sizeof(ty) as a compile-time integer literal.
Node * __builtin_ast_node_inc(Node *node)
Return the increment of a for node.
void __builtin_ast_pop_switch(void)
Node * __builtin_ast_int_literal(int64_t value)
Build an integer literal AST node.
Node * __builtin_ast_cas_desired(Node *node)
Return the desired-value operand of an NK_CAS.
const char * __builtin_ast_asm_operand_name(Node *node, int index)
Return the symbolic name of an asm operand.
Node * __builtin_ast_publish_type(Type *ty, Token *tok)
Accept a generated type declaration as already published.
const char * __builtin_dump_tree_to_string(Node *node)
Render the tree representation to a heap-allocated string.
int64_t __builtin_ast_enum_constant_value(EnumConstant *ec)
Return the integer value of an enum constant.
Type * __builtin_ast_make_pointer(Type *base)
Build a pointer-to-base type.
bool __builtin_ast_obj_is_definition(Obj *obj)
Test whether a global object has a definition.
int __builtin_ast_asm_goto_label_count(Node *node)
Return the number of jump labels of an asm goto.
void __builtin_ast_pop_loop(void)
Restore the loop context saved by the most recent push.
int __builtin_ast_member_offset(Member *m)
Return the byte offset of a struct/union member.
const char * __builtin_ast_enum_name(Type *e)
Return the tag name of an enum type.
AttrTargetKind
Discriminates the kind of declaration an AttrTarget refers to, returned by GetAttrTargetKind(target) ...
Definition reflection.h:275
@ ATTR_TARGET_PARAM
Definition reflection.h:281
@ ATTR_TARGET_TYPE
Definition reflection.h:277
@ ATTR_TARGET_GLOBAL
Definition reflection.h:279
@ ATTR_TARGET_MEMBER
Definition reflection.h:280
@ ATTR_TARGET_FUNCTION
Definition reflection.h:278
@ ATTR_TARGET_TYPEDEF
Definition reflection.h:276
NodeKind __builtin_ast_node_kind(Node *node)
Return the kind of a node.
void __builtin_ast_function_set_variadic(Obj *fn, bool is_variadic)
Set whether a function is variadic.
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_node_rhs(Node *node)
Return the right operand of a node.
Node * __builtin_ast_funcall(Node *callee, Node **args, int n)
Create a function call node.
int __builtin_ast_member_has_attr(Member *m, const char *name)
Return 1 if the member carries the custom attribute name.
bool __builtin_ast_const_int_value(Node *node, int64_t *out)
Evaluate an integer constant expression node.
Node * __builtin_ast_block_add_current_stmt(Node *stmt)
int __builtin_ast_bitop_op(Node *node)
Return the operation of an NK_BITOP.
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 e...
const char * __builtin_ast_string_literal_value(Node *node)
Return the text of a string literal node.
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...
void __builtin_ast_push_struct(Type *ty)
Establish a struct or union as the current field-add context.
void __builtin_ast_function_add_param(Obj *fn, const char *name, Type *type)
Add a parameter to a function.
int __builtin_ast_type_size(Type *ty)
Return sizeof(ty) in bytes.
Type * __builtin_ast_type_base(Type *ty)
Return the element type of a pointer or array.
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_switch_case_at(Node *sw, int index)
Return a case label of a switch, in source order.
int __builtin_ast_global_count(void)
Return the total number of global symbols.
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.
Node * __builtin_quote_lazy(const char *tmpl,...)
Deferred (unparsed) quasi-quote: captures a template and its splice arguments without parsing it.
Type * __builtin_ast_struct_add_current_field(const char *name, Type *field_type)
Type * __builtin_ast_member_type(Member *m)
Return the type of a struct/union member.
int64_t __builtin_ast_enum_value(Type *e, int index)
Return the integer value of the enum constant at the given index.
int __builtin_ast_asm_clobber_count(Node *node)
Return the number of clobbers of an NK_ASM statement.
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.
void __builtin_ast_push_switch(Node *switch_node)
Establish a switch node as the current case/default context.
Node * __builtin_ast_while(Node *cond, Node *body)
Create a while loop node.
const char * __builtin_ast_param_attr_name_at(Type *p, int index)
Return the name of the parameter's attribute use index, or NULL.
void __builtin_ast_switch_set_current_default(Node *body)
Node * __builtin_get_constexpr_value(const char *name)
Read the evaluated initializer of a global constexpr variable as an AST literal node.
int __builtin_ast_enum_value_count(Type *e)
Return the number of values in an enum type.
int __builtin_ast_atomic_fail_order(Node *node)
Return the failure memory order of an NK_CAS.
Node * __builtin_ast_local_var_unique(Type *ty)
Declare a hygienic (gensym'd) local variable in the current function scope and return a variable-refe...
int __builtin_ast_call_arg_count(Node *call)
Return the number of arguments of a call.
Node * __builtin_ast_init_array(Type *elem_ty, Node **elems, int n)
Build an array compound literal. Element type is explicit to avoid long-inference surprises with Make...
Node * __builtin_macroexpand_1(Node *node)
Lisp-style single-step macro expansion (macroexpand-1 semantics).
const char * __builtin_ast_asm_clobber_at(Node *node, int index)
Return a clobber of an NK_ASM statement.
Node * __builtin_ast_node_else(Node *node)
Return the else-branch of an if or ?: node.
Type * __builtin_ast_type_return_type(Type *ty)
Return the return type of a function type.
Node * __builtin_ast_block(Node **stmts, int count)
Build a block (compound statement) node.
Node * __builtin_ast_param_ref(Obj *fn, const char *name)
Build a reference to a function parameter by name.
const char * __builtin_ast_macro_call_name(Node *node)
Return the macro name of a not-yet-expanded NK_MACRO_CALL.
Node * __builtin_ast_unary(NodeKind op, Node *operand)
Build a unary operation AST node.
Node * __builtin_ast_if(Node *cond, Node *then_body, Node *else_body)
Build an if statement node.
void __builtin_ast_switch_add_current_case(Node *value, Node *body)
AstOverflowOp
The operation of an NK_OVERFLOW_ARITH node, returned by OverflowOp(node).
Definition reflection.h:266
@ AST_OVERFLOW_MUL
Definition reflection.h:269
@ AST_OVERFLOW_ADD
Definition reflection.h:267
@ AST_OVERFLOW_SUB
Definition reflection.h:268
Obj * __builtin_attr_target_obj(AttrTarget *target)
Return the decorated function or global object, or NULL for type targets.
EnumConstant * __builtin_ast_enum_find(Type *enum_type, const char *name)
Look up an enum constant by name.
int __builtin_ast_type_align(Type *ty)
Return _Alignof(ty) in bytes.
const char * __builtin_dump_ast_gen_to_string(Node *node)
Render the __builtin_ast_*() builder call sequence to a string.
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...
Node * __builtin_ast_node_init(Node *node)
Return the initialiser of a for node.
Node * __builtin_get_comptime_ptr(const char *name)
Return the address of a comptime variable as a generated-code AST pointer node.
void __builtin_ast_function_set_static(Obj *fn, bool is_static)
Set whether a function has static linkage.
bool __builtin_ast_fence_is_signal(Node *node)
Return whether an NK_FENCE is a signal fence.
void __builtin_ast_enum_add_current_constant(const char *name, int value)
const char * __builtin_gensym(const char *prefix)
Generate a unique identifier string for macro-created symbols.
int __builtin_ast_type_param_count(Type *ty)
Return the number of declared parameters of a function type.
void __builtin_ast_switch_add_case(Node *switch_node, Node *value, Node *body)
Append a case to a switch statement.
bool __builtin_ast_obj_is_static(Obj *obj)
Test whether a global object has internal (static) linkage.
Node * __builtin_ast_node_then(Node *node)
Return the then-branch of an if or ?: node, or the body of a loop or switch.
Obj * __builtin_ast_global_var(const char *name, Type *ty)
Create a new named global variable definition.
Obj * __builtin_ast_global_at(int index)
Return the global symbol at the given index.
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 eleme...
int __builtin_ast_param_attr_count(Type *p)
Return the number of custom attribute uses on the parameter.
void __builtin_emit_directive(const char *line)
Emit one raw preprocessor directive line into generated output.
int64_t __builtin_get_comptime_int(const char *name)
Read an integer-typed #pragma comptime variable's value at compile time.
const char * __builtin_ast_asm_goto_label_at(Node *node, int index)
Return a jump label name of an asm goto.
void __builtin_ast_pop_fn(void)
Restore the function context saved by the most recent push.
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 in...
Obj * __builtin_ast_node_var_obj(Node *node)
Return the variable an NK_VAR (or NK_MEMZERO) node refers to.
Node * __builtin_ast_node_next(Node *node)
Return the next node in a statement or argument list.
const char * __builtin_ast_member_name(Member *m)
Return the name of a struct/union member.
void __builtin_ast_pop_block(void)
void __builtin_dump_ast_gen(Node *node)
Print __builtin_ast_*() builder calls that would reconstruct the node.
int __builtin_ast_block_count(Node *block)
Return the number of statements in an NK_BLOCK or NK_STMT_EXPR.
const char * __builtin_ast_asm_template(Node *node)
Return the template string of an NK_ASM statement.
int __builtin_ast_member_attr_count(Member *m)
Return the number of custom attribute uses on the member.
int __builtin_attr_target_kind(AttrTarget *target)
Return the kind of declaration decorated by a custom attribute.
Node * __builtin_ast_binary(NodeKind op, Node *left, Node *right)
Build a binary operation AST node.
void __builtin_ast_global_var_set_init_data(Obj *var, const char *data, int len)
Set the initial data for a generated global variable.
Node * __builtin_ast_publish(Obj *obj, Token *tok)
Make a generated object visible at the current source position.
int __builtin_ast_atomic_order(Node *node)
Return the memory order of an NK_CAS, NK_EXCH, NK_ALOAD or NK_ASTORE.
Node * __builtin_ast_node_strip_implicit(Node *node)
Peel compiler-inserted casts and call wrappers off a node.
AstJumpKind
Which statement an NK_GOTO node came from, returned by GotoJumpKind(node).
Definition reflection.h:248
@ AST_JUMP_BREAK
Definition reflection.h:250
@ AST_JUMP_CONTINUE
Definition reflection.h:251
@ AST_JUMP_GOTO
Definition reflection.h:249
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.
Obj * __builtin_ast_function_prototype(const char *name, Type *return_type)
Create a function forward declaration (prototype) without a body.
EnumConstant * __builtin_ast_enum_at(Type *enum_type, int index)
Return the enum constant at a given index.
Node * __builtin_ast_copy_location(Node *dst, Node *src)
Copy the source token from one node to another.
Node * __builtin_ast_null(void)
Build a typed null pointer node: (void *)0.
int __builtin_ast_bitop_width(Node *node)
Return the bit width of an NK_BITOP's builtin.
const char * __builtin_ast_enum_value_name(Type *e, int index)
Return the name of the enum constant at the given index.
Node * __builtin_ast_cas_addr(Node *node)
Return the address operand of an NK_CAS.
const char * __builtin_ast_type_c_name(Type *ty)
Return a valid C identifier fragment naming ty.
void __builtin_ast_push_block(Node *block)
Establish a block as the current statement-append context.
void __builtin_ast_push_enum(Type *ty)
Establish an enum as the current constant-add context.
long long __builtin_ast_node_int_value(Node *node)
Return the value of an integer NK_NUM literal.
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.
int __builtin_ast_function_local_count(Obj *fn)
Return the number of source-level locals of a function definition.
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)".
Node * __builtin_ast_subscript(Node *arr, Node *idx)
Build an array subscript node: arr[idx], desugared as *(arr+idx).
bool __builtin_ast_asm_is_goto(Node *node)
Return whether an NK_ASM statement is an asm goto.
int __builtin_ast_goto_jump_kind(Node *node)
Return which statement an NK_GOTO came from.
Node * __builtin_ast_loop_set_body(Node *loop, Node *body)
Attach body to loop (a node from MakeWhile/MakeFor/MakeDoWhile).
void __builtin_generate_sum(Type *elem_ty)
Publish T sum_T(T *arr, size_t n) summing all elements.
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 e...
int __builtin_ast_asm_output_count(Node *node)
Return the number of output operands of an NK_ASM statement.
void __builtin_ast_push_loop(Node *loop)
Establish loop as the current loop context, so an eagerly-parsed Quote("break;")/Quote("continue;") c...
Obj * __builtin_ast_function_param_at(Obj *fn, int index)
Return a parameter of a function definition, in declaration order.
bool __builtin_ast_atomic_is_weak(Node *node)
Return whether an NK_CAS was written as a weak compare-exchange.
Obj * __builtin_ast_function_local_at(Obj *fn, int index)
Return a local variable of a function definition, in declaration order.
Node * __builtin_ast_float_literal(double value)
Build a floating-point literal AST node.
Node * __builtin_ast_case_body(Node *node)
Return the statement that follows an NK_CASE label.
bool __builtin_ast_member_is_bitfield(Member *m)
Test whether a member is a bitfield.
Obj * __builtin_ast_obj_next(Obj *obj)
Return the next Obj in the list that holds obj.
Type * __builtin_ast_find_type(const char *name)
Look up a type by tag name (struct/union/enum).
void __builtin_ast_function_set_inline(Obj *fn, bool is_inline)
Set whether a function is inline.
void __builtin_ast_pop_struct(void)
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_block_at(Node *block, int index)
Return a statement of an NK_BLOCK or NK_STMT_EXPR.
Node * __builtin_ast_function_body(Obj *fn)
Return the top-level block of a function definition.
const char * __builtin_ast_asm_operand_constraint(Node *node, int index)
Return the constraint string of an asm operand.
TypeKind __builtin_ast_type_kind(Type *ty)
Return the TypeKind tag of a type.
const char * __builtin_attr_target_name(AttrTarget *target)
Return the decorated declaration's source name, when available.
int __builtin_ast_switch_case_count(Node *sw)
Return the number of case labels of a switch (excluding default).
Node * __builtin_ast_switch(Node *cond)
Build a switch statement node.
TypeKind
Discriminates the kind of a Type: primitive, pointer, array, function, struct/union,...
Definition reflection.h:152
@ TK_FUNC
Definition reflection.h:164
@ TK_VLA
Definition reflection.h:166
@ TK_SHORT
Definition reflection.h:156
@ TK_BOOL
Definition reflection.h:154
@ TK_PTR
Definition reflection.h:163
@ TK_FLOAT
Definition reflection.h:159
@ TK_STRUCT
Definition reflection.h:167
@ TK_DOUBLE
Definition reflection.h:160
@ TK_UNION
Definition reflection.h:168
@ TK_LONG
Definition reflection.h:158
@ TK_INT
Definition reflection.h:157
@ TK_ARRAY
Definition reflection.h:165
@ TK_LDOUBLE
Definition reflection.h:161
@ TK_ENUM
Definition reflection.h:162
@ TK_VOID
Definition reflection.h:153
@ TK_CHAR
Definition reflection.h:155
void __builtin_ast_switch_set_default(Node *switch_node, Node *body)
Set the default case for a switch statement.
Node * __builtin_ast_var_ref(const char *name)
Build a variable reference AST node.
Member * __builtin_ast_node_member(Node *node)
Return the member an NK_MEMBER node selects.
void __builtin_ast_function_set_body(Obj *fn, Node *body)
Set the body of a function.
int __builtin_ast_enum_count(Type *enum_type)
Return the number of constants in an enum type.
int __builtin_ast_type_array_len(Type *ty)
Return the fixed length of an array type.
Node * __builtin_ast_return(Node *expr)
Build a return statement node.
Node * __builtin_ast_overflow_result_ptr(Node *node)
Return the result pointer of an NK_OVERFLOW_ARITH.
Type * __builtin_ast_make_array(Type *base, int length)
Build a fixed-length array type.
Type * __builtin_ast_make_const(Type *ty)
Return a const-qualified copy of ty.
Node * __builtin_ast_member(Node *obj, const char *name)
Create a struct/union member access node (obj.name).
Obj * __builtin_ast_find_global(const char *name)
Look up a global symbol by name.
Node ** __builtin_ast_varargs_as_array(void)
Return an inline macro's variadic AST arguments as an array.
const char * __builtin_ast_type_name(Type *ty)
Return the user-visible name of a type, if any.
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_local_var(const char *name, Type *ty)
Declare a named local variable in the current function scope and return a variable-reference node for...
Type * __builtin_attr_target_param(AttrTarget *target)
Return the attributed parameter's type of an ATTR_TARGET_PARAM target, else NULL.
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)....
int __builtin_ast_asm_input_count(Node *node)
Return the number of input operands of an NK_ASM statement.
Node * __builtin_ast_block_add_stmt(Node *block, Node *stmt)
Append a statement to a block node.
Node * __builtin_ast_call_arg_at(Node *call, int index)
Return an argument of a call.
const char * __builtin_ast_label_name(Node *node)
Return the name of an NK_GOTO, NK_LABEL or NK_LABEL_VAL.
double __builtin_ast_node_float_value(Node *node)
Return the value of a floating NK_NUM literal.
int64_t __builtin_ast_offsetof_chain(Type *ty, const char **names, int n)
Compute the byte offset of a (possibly nested) member chain.
bool __builtin_ast_type_is_variadic(Type *ty)
Test whether a function type is variadic.
Type * __builtin_ast_get_type(const char *name)
Look up a type by name, resolving standard base-type spellings.
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.
Token * __builtin_ast_token_from_node(Node *node)
Return the opaque source token attached to a node.
Member * __builtin_ast_struct_member_at(Type *struct_type, int index)
Return the member at the given index.
Node * __builtin_ast_cond(Node *cond, Node *then_expr, Node *else_expr)
Build a ternary conditional expression node (cond ? then : else).
Node * __builtin_ast_cast(Node *expr, Type *target_type)
Build a type cast AST node.
const char * __builtin_ast_enum_constant_name(EnumConstant *ec)
Return the name of an enum constant.
Type * __builtin_ast_make_union(const char *name)
Create and expose a new named union type.
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....
void __builtin_ast_pop_enum(void)
Node * __builtin_ast_macro_call_arg_at(Node *node, int index)
Return an argument of an NK_MACRO_CALL.
Node * __builtin_get_comptime_var(const char *name)
Read a comptime scalar variable as an AST literal node.
Node * __builtin_ast_for(Node *init, Node *cond, Node *inc, Node *body)
Create a for loop node.
Node * __builtin_ast_call_callee(Node *call)
Return the callee expression of a call.
NodeKind
Discriminates the operator/statement kind of a Node, e.g. as passed to MakeBinary / MakeUnary,...
Definition reflection.h:176
@ NK_ASTORE
Definition reflection.h:235
@ NK_DECIMAL_TO_CHARS
Definition reflection.h:239
@ NK_ASSIGN
Definition reflection.h:193
@ NK_BITOR
Definition reflection.h:185
@ NK_FUNCALL
Definition reflection.h:214
@ NK_CAS
Definition reflection.h:223
@ NK_VAR
Definition reflection.h:217
@ NK_COND
Definition reflection.h:194
@ NK_CAST
Definition reflection.h:220
@ NK_ASM
Definition reflection.h:222
@ NK_DYNOBJ_SIZE
Definition reflection.h:237
@ NK_BITAND
Definition reflection.h:184
@ NK_LE
Definition reflection.h:192
@ NK_SWITCH
Definition reflection.h:207
@ NK_MACRO_CALL
Definition reflection.h:228
@ NK_BLOCK
Definition reflection.h:209
@ NK_MEMZERO
Definition reflection.h:221
@ NK_DO
Definition reflection.h:206
@ NK_FRAME_ADDR
Definition reflection.h:225
@ NK_NUM
Definition reflection.h:219
@ NK_FOR
Definition reflection.h:205
@ NK_SHL
Definition reflection.h:187
@ NK_LT
Definition reflection.h:191
@ NK_DYNAMIC_CHECK
Definition reflection.h:242
@ NK_LABEL_VAL
Definition reflection.h:213
@ NK_GOTO
Definition reflection.h:210
@ NK_RETURN_ADDR
Definition reflection.h:236
@ NK_STMT_EXPR
Definition reflection.h:216
@ NK_CASE
Definition reflection.h:208
@ NK_FENCE
Definition reflection.h:240
@ NK_NULL_EXPR
Definition reflection.h:177
@ NK_EXPR_STMT
Definition reflection.h:215
@ NK_NE
Definition reflection.h:190
@ NK_QUOTE_LAZY
Definition reflection.h:241
@ NK_NOT
Definition reflection.h:199
@ NK_COMPLEX
Definition reflection.h:229
@ NK_UNREACHABLE
Definition reflection.h:230
@ NK_BLOCK_LITERAL
Definition reflection.h:226
@ NK_LOGAND
Definition reflection.h:201
@ NK_BITXOR
Definition reflection.h:186
@ NK_IF
Definition reflection.h:204
@ NK_NEG
Definition reflection.h:182
@ NK_BITOP
Definition reflection.h:231
@ NK_EXCH
Definition reflection.h:224
@ NK_VLA_PTR
Definition reflection.h:218
@ NK_LOGOR
Definition reflection.h:202
@ NK_GOTO_EXPR
Definition reflection.h:211
@ NK_EQ
Definition reflection.h:189
@ NK_INIT_SPLICE
Definition reflection.h:233
@ NK_COMMA
Definition reflection.h:195
@ NK_BLOCK_CALL
Definition reflection.h:227
@ NK_DEREF
Definition reflection.h:198
@ NK_ADD
Definition reflection.h:178
@ NK_VA_NAMED_COUNT
Definition reflection.h:243
@ NK_MOD
Definition reflection.h:183
@ NK_ALOAD
Definition reflection.h:234
@ NK_ADDR
Definition reflection.h:197
@ NK_RETURN
Definition reflection.h:203
@ NK_SHR
Definition reflection.h:188
@ NK_BITNOT
Definition reflection.h:200
@ NK_CONVERTVECTOR
Definition reflection.h:238
@ NK_OVERFLOW_ARITH
Definition reflection.h:232
@ NK_DIV
Definition reflection.h:181
@ NK_MUL
Definition reflection.h:180
@ NK_SUB
Definition reflection.h:179
@ NK_LABEL
Definition reflection.h:212
@ NK_MEMBER
Definition reflection.h:196
bool __builtin_ast_asm_is_volatile(Node *node)
Return whether an NK_ASM statement is written volatile.
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...
Node * __builtin_ast_vararg_at(int index)
Return an inline macro's variadic AST argument by zero-based index.
Node * __builtin_ast_asm_operand_expr(Node *node, int index)
Return the expression of an asm operand.
Node * __builtin_ast_do_while(Node *body, Node *cond)
Create a do-while loop node.
Member * __builtin_attr_target_member(AttrTarget *target)
Return the attributed member of an ATTR_TARGET_MEMBER target, else NULL.
int __builtin_ast_member_bitfield_width(Member *m)
Return the bit width of a bitfield member.
void void Node * __builtin_quote(const char *tmpl,...)
Parse a C code template string into an AST node, substituting splice points with the provided argumen...
Node * __builtin_ast_node_cond(Node *node)
Return the condition of an if, loop, switch or ?: node.
Node * __builtin_ast_comma(Node *lhs, Node *rhs)
Build a comma expression: evaluate lhs, yield rhs.
const char * __builtin_ast_obj_name(Obj *obj)
Return the name of a global object.
Node * __builtin_ast_cas_expected(Node *node)
Return the expected-value operand of an NK_CAS.
bool __builtin_ast_type_exists(const char *name)
Check whether a type is currently in scope by name.
Node * __builtin_ast_alignof_type(Type *ty)
Emit _Alignof(ty) as a compile-time integer literal.
Node * __builtin_ast_assign(Node *target, Node *value)
Build an assignment node (target = value).
void __builtin_ast_add_attribute(Obj *fn, const char *attr_text)
Apply an attribute string to a programmatically created function.
int __builtin_ast_macro_call_arg_count(Node *node)
Return the argument count of an NK_MACRO_CALL.
Node * __builtin_ast_node_body(Node *node)
Return the statement list of an NK_BLOCK or NK_STMT_EXPR.
bool __builtin_ast_type_is_const(Type *ty)
Test whether a type is const-qualified.
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.
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_attr_target_param_index(AttrTarget *target)
Return the position of an ATTR_TARGET_PARAM target in its parameter list, else -1.
void __builtin_ast_add_build_target_attr(Obj *fn, const char *kind)
long long __builtin_ast_case_begin(Node *node)
Return the first value of an NK_CASE label.
Type * __builtin_ast_node_type(Node *node)
Return the resolved type of an expression node.
Token * __builtin_ast_synthetic_token(const char *label)
Create an opaque synthetic source token for generated AST nodes.
const char * __builtin_ast_member_attr_name_at(Member *m, int index)
Return the name of the member's attribute use index, or NULL.
Obj * __builtin_ast_function(const char *name, Type *return_type)
Create a new function object.
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.
void __builtin_dump_tree(Node *node)
Print a human-readable tree representation of a node to stdout.
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 ...
Type * __builtin_ast_type_param_at(Type *ty, int index)
Return the type of the parameter at the given index.
Type * __builtin_ast_make_enum(const char *name)
Create and expose a new named enum type.
Node * __builtin_ast_set_token(Node *node, Token *tok)
Attach an opaque source token to a node.
Node * __builtin_quote_lazy_n(const char *tmpl, Node **nodes, int count)
Array-form deferred quasi-quote; see __builtin_quote_lazy.