CCCC
C bytecode compiler + VM interpreter
Loading...
Searching...
No Matches
reflection.h
Go to the documentation of this file.
1/*
2 CCCC: Comprehensiev C Compensation Compiler - Comptime Reflection API
3
4 Copyright (C) 2025 George Watson
5
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <https://www.gnu.org/licenses/>.
18*/
19
85#ifndef CCCC_REFLECTION_H
86#define CCCC_REFLECTION_H
87
88#include <stdbool.h>
89#include <stddef.h>
90#include <stdint.h>
91#include <string.h>
92
93#ifdef __cplusplus
94extern "C" {
95#endif
96
97// Forward declarations (opaque types for comptime functions)
98
99// Reserved tag spellings keep these handles from colliding with a user's own
100// `struct Node`, `union Type`, ... in the comptime scope. cccc's own sources
101// define __CCCC_TAG(n) as `n` to match their internal struct names.
102#ifndef __CCCC_TAG
103#define __CCCC_TAG(n) __cccc_##n
104#endif
105
109typedef struct __CCCC_TAG(VirtualMachine) VirtualMachine;
110
114typedef struct __CCCC_TAG(Type) Type;
115
120typedef struct __CCCC_TAG(Node) Node;
121
125typedef struct __CCCC_TAG(Obj) Obj;
126
130typedef struct __CCCC_TAG(Member) Member;
131
134typedef struct __CCCC_TAG(EnumConstant) EnumConstant;
135
139typedef struct __CCCC_TAG(Token) Token;
140
145typedef struct __CCCC_TAG(AttrTarget) AttrTarget;
146
147#ifndef CCCC_REFLECTION_PROTOTYPES_ONLY
170
245
253
263
271
283#endif // CCCC_REFLECTION_PROTOTYPES_ONLY
284
290const char *__builtin_gensym(const char *prefix);
291
301Node *__builtin_macroexpand_1(Node *node);
302
312Node *__builtin_macroexpand(Node *node);
313
318
325Node *__builtin_ast_vararg_at(int index);
326
337
344const char *__builtin_ast_vararg_str_at(int index);
345
346// ============================================================================
347// Generated Node Source Locations (ticket #173)
348// ============================================================================
349
356
364Token *__builtin_ast_synthetic_token(const char *label);
365
372
381Node *__builtin_ast_set_token(Node *node, Token *tok);
382
389Node *__builtin_ast_copy_location(Node *dst, Node *src);
390
404
405// ============================================================================
406// Macro Diagnostics (ticket #78)
407// ============================================================================
408
419void __builtin_macro_error_at(Node *node, const char *fmt, ...)
420 __attribute__((format(printf, 2, 3)));
421
429void __builtin_macro_warning_at(Node *node, const char *fmt, ...)
430 __attribute__((format(printf, 2, 3)));
431
462Node *__builtin_quote(const char *tmpl, ...);
463
474Node *__builtin_quote_n(const char *tmpl, Node **nodes, int count);
475
499Node *__builtin_quote_lazy(const char *tmpl, ...);
500
509Node *__builtin_quote_lazy_n(const char *tmpl, Node **nodes, int count);
510
522Node *__builtin_node_list(Node **nodes, int count);
523
524// ============================================================================
525// Type Lookup and Introspection
526// ============================================================================
527
533Type *__builtin_ast_find_type(const char *name);
534
540bool __builtin_ast_type_exists(const char *name);
541
553Type *__builtin_ast_get_type(const char *name);
554
561
568
575
582
589
596
603
610
617
624Type *__builtin_ast_type_param_at(Type *ty, int index);
625
632
639const char *__builtin_ast_type_name(Type *ty);
640
648const char *__builtin_ast_type_c_name(Type *ty);
649
656
663Type *__builtin_ast_make_array(Type *base, int length);
664
674Type *__builtin_ast_make_func_ptr_type(Type *return_ty, Type **param_types,
675 int nparams);
676
677// Ticket #171: qualified type constructors
690
691// ============================================================================
692// Enum Reflection
693// ============================================================================
694
700int __builtin_ast_enum_count(Type *enum_type);
701
708EnumConstant *__builtin_ast_enum_at(Type *enum_type, int index);
709
716EnumConstant *__builtin_ast_enum_find(Type *enum_type, const char *name);
717
723const char *__builtin_ast_enum_constant_name(EnumConstant *ec);
724
731int64_t __builtin_ast_enum_constant_value(EnumConstant *ec);
732
738const char *__builtin_ast_enum_name(Type *e);
739
746
753const char *__builtin_ast_enum_value_name(Type *e, int index);
754
761int64_t __builtin_ast_enum_value(Type *e, int index);
762
771Node *__builtin_ast_enum_to_string_switch(Type *ty, Node *expr);
772
781Node *__builtin_ast_enum_from_string_chain(Type *ty, Node *expr);
782
783// ============================================================================
784// Struct/Union Member Introspection
785// ============================================================================
786
793
800Member *__builtin_ast_struct_member_at(Type *struct_type, int index);
801
808Member *__builtin_ast_struct_member_find(Type *struct_type, const char *name);
809
815const char *__builtin_ast_member_name(Member *m);
816
823
830
837
844
852int64_t __builtin_ast_offsetof_chain(Type *ty, const char **names, int n);
853
854// ============================================================================
855// Global Symbol Introspection
856// ============================================================================
857
863Obj *__builtin_ast_find_global(const char *name);
864
870
877
883const char *__builtin_ast_obj_name(Obj *obj);
884
891
898
905
912
919
926
933Obj *__builtin_ast_function_param_at(Obj *fn, int index);
934
941
949Obj *__builtin_ast_function_local_at(Obj *fn, int index);
950
957
964
970Type *__builtin_ast_node_type(Node *node);
971
977Node *__builtin_ast_node_next(Node *node);
978
984Node *__builtin_ast_node_lhs(Node *node);
985
991Node *__builtin_ast_node_rhs(Node *node);
992
998Node *__builtin_ast_node_body(Node *node);
999
1005Node *__builtin_ast_node_cond(Node *node);
1006
1013Node *__builtin_ast_node_then(Node *node);
1014
1020Node *__builtin_ast_node_else(Node *node);
1021
1027Node *__builtin_ast_node_init(Node *node);
1028
1034Node *__builtin_ast_node_inc(Node *node);
1035
1042
1049Node *__builtin_ast_block_at(Node *block, int index);
1050
1057
1064
1071Node *__builtin_ast_call_arg_at(Node *call, int index);
1072
1078long long __builtin_ast_node_int_value(Node *node);
1079
1086
1093
1099Member *__builtin_ast_node_member(Node *node);
1100
1107
1114Node *__builtin_ast_switch_case_at(Node *sw, int index);
1115
1122
1128long long __builtin_ast_case_begin(Node *node);
1129
1136long long __builtin_ast_case_end(Node *node);
1137
1143Node *__builtin_ast_case_body(Node *node);
1144
1150const char *__builtin_ast_macro_call_name(Node *node);
1151
1158
1165Node *__builtin_ast_macro_call_arg_at(Node *node, int index);
1166
1174
1180const char *__builtin_ast_label_name(Node *node);
1181
1189
1195const char *__builtin_ast_asm_template(Node *node);
1196
1203
1210
1217const char *__builtin_ast_asm_operand_constraint(Node *node, int index);
1218
1225const char *__builtin_ast_asm_operand_name(Node *node, int index);
1226
1233Node *__builtin_ast_asm_operand_expr(Node *node, int index);
1234
1241
1248const char *__builtin_ast_asm_clobber_at(Node *node, int index);
1249
1256
1263
1270
1277const char *__builtin_ast_asm_goto_label_at(Node *node, int index);
1278
1286
1293
1300
1306Node *__builtin_ast_cas_addr(Node *node);
1307
1315
1322
1329
1336
1344
1351
1359
1362int __builtin_attr_target_kind(AttrTarget *target);
1363
1366const char *__builtin_attr_target_name(AttrTarget *target);
1367
1370Type *__builtin_attr_target_type(AttrTarget *target);
1371
1375Obj *__builtin_attr_target_obj(AttrTarget *target);
1376
1379Token *__builtin_attr_target_token(AttrTarget *target);
1380
1384Member *__builtin_attr_target_member(AttrTarget *target);
1385
1389Type *__builtin_attr_target_owner(AttrTarget *target);
1390
1394Type *__builtin_attr_target_param(AttrTarget *target);
1395
1400
1403int __builtin_ast_member_has_attr(Member *m, const char *name);
1404
1408int __builtin_ast_member_attr_arg_count(Member *m, const char *name);
1409
1412Node *__builtin_ast_member_attr_arg(Member *m, const char *name, int index);
1413
1417
1420const char *__builtin_ast_member_attr_name_at(Member *m, int index);
1421
1426
1429Node *__builtin_ast_member_attr_arg_at(Member *m, int index, int arg);
1430
1434int __builtin_ast_param_has_attr(Type *p, const char *name);
1435
1439int __builtin_ast_param_attr_arg_count(Type *p, const char *name);
1440
1444Node *__builtin_ast_param_attr_arg(Type *p, const char *name, int index);
1445
1449
1452const char *__builtin_ast_param_attr_name_at(Type *p, int index);
1453
1458
1462Node *__builtin_ast_param_attr_arg_at(Type *p, int index, int arg);
1463
1464// ============================================================================
1465// AST Node Construction - Literals
1466// ============================================================================
1467
1473Node *__builtin_ast_int_literal(int64_t value);
1474
1481
1487Node *__builtin_ast_string_literal(const char *str);
1488
1496
1504bool __builtin_ast_const_int_value(Node *node, int64_t *out);
1505
1514bool __builtin_ast_const_uint_value(Node *node, uint64_t *out);
1515
1521Node *__builtin_ast_var_ref(const char *name);
1522
1530Node *__builtin_ast_param_ref(Obj *fn, const char *name);
1531
1532// ============================================================================
1533// AST Node Construction - Expressions
1534// ============================================================================
1535
1543Node *__builtin_ast_binary(NodeKind op, Node *left, Node *right);
1544
1551Node *__builtin_ast_unary(NodeKind op, Node *operand);
1552
1559Node *__builtin_ast_cast(Node *expr, Type *target_type);
1560
1561// Ticket #171: new expression builders
1562
1570Node *__builtin_ast_cond(Node *cond, Node *then_expr, Node *else_expr);
1571
1577
1584
1591
1598
1605Node *__builtin_ast_subscript(Node *arr, Node *idx);
1606
1613Node *__builtin_ast_comma(Node *lhs, Node *rhs);
1614
1615// ============================================================================
1616// AST Node Construction - Statements
1617// ============================================================================
1618
1625Node *__builtin_ast_return(Node *expr);
1626
1633Node *__builtin_ast_block(Node **stmts, int count);
1634
1642Node *__builtin_ast_block_add_stmt(Node *block, Node *stmt);
1643
1651Node *__builtin_ast_if(Node *cond, Node *then_body, Node *else_body);
1652
1659Node *__builtin_ast_switch(Node *cond);
1660
1668void __builtin_ast_switch_add_case(Node *switch_node, Node *value, Node *body);
1669
1676void __builtin_ast_switch_set_default(Node *switch_node, Node *body);
1677
1683Node *__builtin_ast_expr_stmt(Node *expr);
1684
1685// ============================================================================
1686// AST Node Construction - Local Variable Injection (ticket #77)
1687// ============================================================================
1688
1701Node *__builtin_ast_local_var(const char *name, Type *ty);
1702
1713
1720Node *__builtin_ast_assign(Node *target, Node *value);
1721
1732Node *__builtin_ast_member(Node *obj, const char *name);
1733
1742Node *__builtin_ast_funcall(Node *callee, Node **args, int n);
1743
1758Node *__builtin_ast_while(Node *cond, Node *body);
1759
1770Node *__builtin_ast_for(Node *init, Node *cond, Node *inc, Node *body);
1771
1779Node *__builtin_ast_do_while(Node *body, Node *cond);
1780
1781// ============================================================================
1782// Loop-building context (ticket #1249)
1783// ============================================================================
1784
1796
1803
1814Node *__builtin_ast_loop_set_body(Node *loop, Node *body);
1815
1816// ============================================================================
1817// Function Generation
1818// ============================================================================
1819
1828Obj *__builtin_ast_function(const char *name, Type *return_type);
1829
1840Node *__builtin_ast_publish(Obj *obj, Token *tok);
1841
1851Node *__builtin_ast_publish_type(Type *ty, Token *tok);
1852
1857void __builtin_emit_directive(const char *line);
1858
1867void __builtin_ast_function_add_param(Obj *fn, const char *name, Type *type);
1868
1875void __builtin_ast_function_set_body(Obj *fn, Node *body);
1876
1882void __builtin_ast_function_set_static(Obj *fn, bool is_static);
1883
1889void __builtin_ast_function_set_inline(Obj *fn, bool is_inline);
1890
1896void __builtin_ast_function_set_variadic(Obj *fn, bool is_variadic);
1897
1898// Ticket #171: function prototype (forward declaration only, no body)
1909Obj *__builtin_ast_function_prototype(const char *name, Type *return_type);
1910
1911// ============================================================================
1912// Programmatic Attribute Application — ticket #619
1913// ============================================================================
1914
1929void __builtin_ast_add_attribute(Obj *fn, const char *attr_text);
1930
1931// Internal helper for MarkAsBuildTarget: composes "cccc::build_target(kind=…)"
1932// at runtime so the macro doesn't require string concatenation.
1933void __builtin_ast_add_build_target_attr(Obj *fn, const char *kind);
1934
1935// Ticket #171: struct/union/enum/typedef type builders
1936
1944Type *__builtin_ast_make_struct(const char *name);
1945
1951Type *__builtin_ast_make_union(const char *name);
1952
1963Type *__builtin_ast_struct_add_field(Type *ty, const char *name,
1964 Type *field_type);
1965
1972Type *__builtin_ast_make_enum(const char *name);
1973
1983void __builtin_ast_enum_add_constant(Type *ty, const char *name, int64_t value);
1984
1993Type *__builtin_ast_make_typedef(const char *name, Type *underlying);
1994
1995// ============================================================================
1996// Global Variable Generation (ticket #152)
1997// ============================================================================
1998
2010Obj *__builtin_ast_global_var(const char *name, Type *ty);
2011
2018void __builtin_ast_global_var_set_init_data(Obj *var, const char *data,
2019 int len);
2020
2026void __builtin_ast_global_var_set_static(Obj *var, bool is_static);
2027
2028// ============================================================================
2029// Function-building context (ticket #148)
2030// ============================================================================
2031
2043
2050
2059
2068 Type *field_type);
2069
2075void __builtin_ast_push_switch(Node *switch_node);
2077void __builtin_ast_switch_add_current_case(Node *value, Node *body);
2079
2087void __builtin_ast_enum_add_current_constant(const char *name, int value);
2088
2089// ============================================================================
2090// AST Dump Functions (ticket #58) — Nim-style dumpTree / dumpAstGen
2091// ============================================================================
2092
2098void __builtin_dump_tree(Node *node);
2099
2105const char *__builtin_dump_tree_to_string(Node *node);
2106
2114void __builtin_dump_ast_gen(Node *node);
2115
2121const char *__builtin_dump_ast_gen_to_string(Node *node);
2122
2123// ============================================================================
2124// Convenience Macros (automatically pass VM)
2125// ============================================================================
2126
2127// Quasi-quoting helpers (ticket #1, #172)
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)
2177// Build a ->next-linked chain from a compound-literal array for $@k splices:
2178// NodeList((Node*[]){ a, b, c }, 3)
2184#define NodeList(nodes, count) __builtin_node_list(nodes, count)
2185
2186// Diagnostic helpers (ticket #78) — note: variadic macros require C99+
2191#define MacroErrorAt(node, ...) __builtin_macro_error_at(node, __VA_ARGS__)
2197#define MacroWarningAt(node, ...) __builtin_macro_warning_at(node, __VA_ARGS__)
2198
2199// AST dump helpers (ticket #58)
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)
2247
2248#define __builtin_dispatch_2(_1, _2, which, ...) which(_1, _2)
2249#define __builtin_dispatch_3(_1, _2, _3, which, ...) which(_1, _2, _3)
2250
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)
2278
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)
2293
2294// Type introspection — no VM needed
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)
2349
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)
2386
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)
2403
2404// Ticket #171: new expression builders
2405// Ternary conditional: cond ? then_expr : else_expr
2412#define MakeCond(c, t, e) __builtin_ast_cond(c, t, e)
2413// Typed null pointer: (void *)0
2416#define MakeNull() __builtin_ast_null()
2417// sizeof(type) / _Alignof(type) as a compile-time integer literal
2421#define MakeSizeofType(ty) __builtin_ast_sizeof_type(ty)
2425#define MakeAlignofType(ty) __builtin_ast_alignof_type(ty)
2426// sizeof(expr): resolves expr's type then returns its size as an integer
2427// literal
2431#define MakeSizeofExpr(expr) __builtin_ast_sizeof_expr(expr)
2432// Array subscript: arr[idx] (desugared as *(arr+idx))
2438#define MakeSubscript(arr, idx) __builtin_ast_subscript(arr, idx)
2439// Comma expression: evaluate lhs (for side effects), yield rhs
2444#define MakeComma(lhs, rhs) __builtin_ast_comma(lhs, rhs)
2445
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)
2540
2541// Thin AST wrappers over <string.h> functions, available via the implicit
2542// #include <string.h> at the top of this header.
2548#define Memcpy(dst, src, n) \
2549 __builtin_ast_funcall(__builtin_ast_var_ref("memcpy"), \
2550 (Node *[]){(dst), (src), (n)}, 3)
2554#define Strlen(s) \
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))
2593
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)
2610
2611// Ticket #171: qualified type constructors
2615#define MakeConst(ty) __builtin_ast_make_const(ty)
2619#define MakeVolatile(ty) __builtin_ast_make_volatile(ty)
2620
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)
2661
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)
2677
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)
2712
2713// ForeachMember(type, varname, body) — host-side (comptime
2714// C) loop over the members of a struct/union type. `varname` is bound to
2715// each Member* in turn; `body` is a compound statement run once per
2716// member at macro-evaluation time (typically building AST nodes via
2717// BlockAddStmt etc.). Two-layer __COUNTER__ indirection gives each
2718// call-site unique loop-variable names so ForeachMember can be nested.
2719#define __builtin_foreach_member_body(type, varname, body, uid) \
2720 do { \
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++) { \
2726 Member *varname = \
2727 StructMemberAt(__builtin_fem_ty_##uid, __builtin_fem_i_##uid); \
2728 body \
2729 } \
2730 } while (0)
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__)
2744
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 *))))
2754
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)
3143
3148#define MakeFunction(name, ret_type) __builtin_ast_function(name, ret_type)
3154#define PublishNode(decl) \
3155 _Generic((decl), \
3156 Obj *: __builtin_ast_publish, \
3157 Type *: __builtin_ast_publish_type)((decl), 0)
3162#define PublishNodeAt(decl, tok) \
3163 _Generic((decl), \
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)
3208
3209// Ticket #171: function forward declaration / prototype builder
3210// Creates a declaration-only Obj (no body); use FunctionAddParam for
3211// parameters and PublishNode to make it visible in scope.
3219#define FunctionPrototype(name, ret) __builtin_ast_function_prototype(name, ret)
3220
3221// Mode attribute registration for AST-generated functions.
3222// Ticket #619: generic attribute application and convenience shorthands.
3223// Use AddAttribute(fn, "cccc::test(suite=\"s\", timeout=5000)") for
3224// fine-grained control.
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)
3245
3246// Ticket #171: struct/union/enum/typedef type builders
3247// Build a new named aggregate and expose it so GetType(name) resolves it.
3248//
3249// Type *s = MakeStruct("Point");
3250// StructAddField(s, "x", GetType("int"));
3251// StructAddField(s, "y", GetType("int"));
3252//
3253// StructAddField works for both struct and union types.
3254// MakeTypedef registers name as an alias for underlying and returns it.
3255// EnumAddConstant adds a constant to the enum AND to scope (usable as int).
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)
3301
3302// Comptime variable access (ticket #188)
3309int64_t __builtin_get_comptime_int(const char *name);
3316double __builtin_get_comptime_float(const char *name);
3322Node *__builtin_get_comptime_var(const char *name);
3330Node *__builtin_get_comptime_ptr(const char *name);
3338Node *__builtin_get_comptime_member(const char *var_name, const char *field);
3339
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)
3365
3366// Constexpr variable access (ticket #189)
3376Node *__builtin_get_constexpr_value(const char *name);
3377
3384#define GetConstexprValue(name) __builtin_get_constexpr_value(name)
3385
3386// ============================================================================
3387// Initializer Builders (ticket #296)
3388// ============================================================================
3389
3396Node *__builtin_ast_compound_literal(Type *ty, Node **inits, int n);
3397
3402Node *__builtin_ast_init_array(Type *elem_ty, Node **elems, int n);
3403
3408Node *__builtin_ast_init_struct(Type *ty, const char **fields, Node **values,
3409 int n);
3410
3418#define CompoundLiteral(ty, ...) \
3419 __builtin_ast_compound_literal( \
3420 ty, (Node *[]){__VA_ARGS__}, \
3421 (int)(sizeof((Node *[]){__VA_ARGS__}) / sizeof(Node *)))
3422
3428#define InitArray(elem_ty, ...) \
3429 __builtin_ast_init_array( \
3430 elem_ty, (Node *[]){__VA_ARGS__}, \
3431 (int)(sizeof((Node *[]){__VA_ARGS__}) / sizeof(Node *)))
3432
3442#define InitStruct(ty, fields, values, n) \
3443 __builtin_ast_init_struct(ty, fields, values, n)
3444
3445// ============================================================================
3446// Serialization
3447// ============================================================================
3448
3459Node *__builtin_ast_serialize(Type *ty, Node *expr, Node *buf);
3460
3467Node *__builtin_ast_deserialize(Type *ty, Node *buf);
3468
3478#define Serialize(ty, expr, buf) __builtin_ast_serialize(ty, expr, buf)
3485#define Deserialize(ty, buf) __builtin_ast_deserialize(ty, buf)
3486
3487// Global variable generation (ticket #152)
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)
3506
3507// Function-building context (ticket #148)
3508// Usage:
3509// WithFn(fn) {
3510// FunctionSetBody(fn, Quote("return 42;"));
3511// }
3512// Inside the block, current_fn is set to fn so Quote("return x;") casts
3513// to the correct return type. The pop always runs even on early exit.
3521#define WithFn(fn) \
3522 for (int _cccc_fn_ctx_ = (__builtin_ast_push_fn((fn)), 1); _cccc_fn_ctx_; \
3523 _cccc_fn_ctx_ = (__builtin_ast_pop_fn(), 0))
3524
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))
3534
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))
3545
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))
3556
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))
3566
3567// GenerateSum/GenerateMap/GenerateReduce/GenerateFilter
3568// -- FP-style array generators. Each publishes a single function named after
3569// elem_ty's spelling (via TypeCName, since builtin scalar types have no
3570// TypeName): sum_<T>, map_<T>, reduce_<T>, filter_<T>. Implemented as plain
3571// C functions in reflection.c (registered via cc_register_cfunc) rather than
3572// @comptime functions, so they're callable from any [[cccc::comptime]] context,
3573// not just from within reflection.h's own macro program.
3574
3578void __builtin_generate_sum(Type *elem_ty);
3579
3584void __builtin_generate_map(Type *elem_ty);
3585
3590void __builtin_generate_reduce(Type *elem_ty);
3591
3597void __builtin_generate_filter(Type *elem_ty);
3598
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)
3618
3619#ifdef __cplusplus
3620}
3621#endif
3622
3623#endif // CCCC_REFLECTION_H
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.