attr.h (1904B)
1 #ifndef KIT_PARSE_ATTR_H 2 #define KIT_PARSE_ATTR_H 3 4 #include "c_support.h" 5 6 /* GNU __attribute__((...)) AST node, shared between the parser (producer) 7 * and the declaration-attribute consumers. The parser builds 8 * the list and chains it onto its carriers (DeclSpecs.attrs, 9 * TagEntry.attrs, SymEntry.attrs); consumers walk a `const Attr*` head 10 * and decode according to `kind`. See doc/ATTRIBUTE.md. */ 11 12 typedef enum AttrKind { 13 ATTR_UNKNOWN = 0, 14 ATTR_PACKED, 15 ATTR_ALIGNED, 16 ATTR_SECTION, 17 ATTR_USED, 18 ATTR_NORETURN, 19 ATTR_ALIAS, 20 ATTR_WEAK, 21 ATTR_VISIBILITY, 22 ATTR_ALWAYS_INLINE, 23 ATTR_NOINLINE, 24 ATTR_UNUSED, 25 ATTR_DEPRECATED, 26 ATTR_WARN_UNUSED_RESULT, 27 ATTR_FORMAT, 28 ATTR_NONNULL, 29 ATTR_RETURNS_NONNULL, 30 ATTR_PURE, 31 ATTR_CONST, 32 ATTR_MALLOC, 33 ATTR_NOTHROW, 34 ATTR_LEAF, 35 ATTR_COLD, 36 ATTR_HOT, 37 ATTR_CONSTRUCTOR, 38 ATTR_DESTRUCTOR, 39 ATTR_CLEANUP, 40 ATTR_MODE, 41 ATTR_VECTOR_SIZE, 42 ATTR_TRANSPARENT_UNION, 43 ATTR_GNU_INLINE, 44 ATTR_FALLTHROUGH, 45 ATTR_SENTINEL, 46 ATTR_NO_INSTRUMENT_FUNCTION, 47 ATTR_NO_SANITIZE, 48 /* Wasm-target import descriptors. Each carries a single string argument 49 * (AS_STRING) stored in `v.sym`. Together they request the wasm backend 50 * emit a `(import "<module>" "<name>" ...)` entry for the declared 51 * function. */ 52 ATTR_IMPORT_MODULE, 53 ATTR_IMPORT_NAME, 54 } AttrKind; 55 56 typedef enum AttrArgShape { 57 AS_NONE, 58 AS_OPTIONAL, 59 AS_INT, 60 AS_INT_OPT, 61 AS_STRING, 62 AS_IDENT, 63 AS_FORMAT, 64 AS_OPAQUE, 65 } AttrArgShape; 66 67 typedef struct Attr Attr; 68 struct Attr { 69 u16 kind; /* AttrKind */ 70 u16 nargs; 71 SrcLoc loc; 72 Sym name; /* canonical (post-underscore-strip) spelling */ 73 union { 74 i64 i; /* aligned(N), vector_size(N), constructor(prio) */ 75 Sym sym; /* section("..."), alias("..."), visibility("...") */ 76 struct { 77 u16 fmt_idx; 78 u16 first; 79 } format; /* format(printf, m, n) */ 80 } v; 81 Attr* next; 82 }; 83 84 #endif