diff options
| author | Zuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian> | 2026-01-27 13:19:23 +0000 |
|---|---|---|
| committer | Zuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian> | 2026-01-27 13:19:23 +0000 |
| commit | 27c0cafdfc66ce731156bf076644716f240318d4 (patch) | |
| tree | cefff28db49f48d12723fb30c41253096bf51ff1 /src/codegen | |
| parent | a3b85c9737b509fd2a792b65aa2365b9bcc9fe6a (diff) | |
Support for custom attributes
Diffstat (limited to 'src/codegen')
| -rw-r--r-- | src/codegen/codegen_decl.c | 32 | ||||
| -rw-r--r-- | src/codegen/codegen_stmt.c | 57 |
2 files changed, 89 insertions, 0 deletions
diff --git a/src/codegen/codegen_decl.c b/src/codegen/codegen_decl.c index eb53911..5fb9f54 100644 --- a/src/codegen/codegen_decl.c +++ b/src/codegen/codegen_decl.c @@ -388,6 +388,38 @@ void emit_struct_defs(ParserContext *ctx, ASTNode *node, FILE *out) { fprintf(out, " __attribute__((visibility(\"default\")))"); } + + if (node->strct.attributes) + { + fprintf(out, " __attribute__(("); + Attribute *custom = node->strct.attributes; + int first = 1; + while (custom) + { + if (!first) + { + fprintf(out, ", "); + } + fprintf(out, "%s", custom->name); + if (custom->arg_count > 0) + { + fprintf(out, "("); + for (int i = 0; i < custom->arg_count; i++) + { + if (i > 0) + { + fprintf(out, ", "); + } + fprintf(out, "%s", custom->args[i]); + } + fprintf(out, ")"); + } + first = 0; + custom = custom->next; + } + fprintf(out, "))"); + } + fprintf(out, ";\n\n"); } else if (node->type == NODE_ENUM) diff --git a/src/codegen/codegen_stmt.c b/src/codegen/codegen_stmt.c index c823b13..bd0c816 100644 --- a/src/codegen/codegen_stmt.c +++ b/src/codegen/codegen_stmt.c @@ -684,9 +684,66 @@ void codegen_node_single(ParserContext *ctx, ASTNode *node, FILE *out) } fprintf(out, "section(\"%s\")", node->func.section); } + + Attribute *custom = node->func.attributes; + while (custom) + { + if (!first) + { + fprintf(out, ", "); + } + fprintf(out, "%s", custom->name); + if (custom->arg_count > 0) + { + fprintf(out, "("); + for (int i = 0; i < custom->arg_count; i++) + { + if (i > 0) + { + fprintf(out, ", "); + } + fprintf(out, "%s", custom->args[i]); + } + fprintf(out, ")"); + } + first = 0; + custom = custom->next; + } + #undef EMIT_ATTR fprintf(out, ")) "); } + else if (node->func.attributes) + { + // Handle case where specific attributes are missing but custom ones exist + fprintf(out, "__attribute__(("); + int first = 1; + Attribute *custom = node->func.attributes; + while (custom) + { + if (!first) + { + fprintf(out, ", "); + } + fprintf(out, "%s", custom->name); + if (custom->arg_count > 0) + { + fprintf(out, "("); + for (int i = 0; i < custom->arg_count; i++) + { + if (i > 0) + { + fprintf(out, ", "); + } + fprintf(out, "%s", custom->args[i]); + } + fprintf(out, ")"); + } + first = 0; + custom = custom->next; + } + fprintf(out, ")) "); + } } if (node->func.is_inline) |
