From e310dbff40e60e878032d59fd7c550398ee34e5d Mon Sep 17 00:00:00 2001 From: Zuhaitz Méndez Fernández de Aránguiz Date: Mon, 26 Jan 2026 02:55:51 +0000 Subject: Fixed duplicate logic and stability issues --- src/codegen/codegen_main.c | 32 ++++++++++++++++---------------- src/codegen/codegen_stmt.c | 14 +------------- 2 files changed, 17 insertions(+), 29 deletions(-) (limited to 'src/codegen') diff --git a/src/codegen/codegen_main.c b/src/codegen/codegen_main.c index 61269ef..6e66bcb 100644 --- a/src/codegen/codegen_main.c +++ b/src/codegen/codegen_main.c @@ -458,15 +458,15 @@ void codegen_node(ParserContext *ctx, ASTNode *node, FILE *out) if (ctx->parsed_globals_list) { - StructRef *s = ctx->parsed_globals_list; - while (s) + StructRef *struct_ref = ctx->parsed_globals_list; + while (struct_ref) { ASTNode *copy = xmalloc(sizeof(ASTNode)); - *copy = *s->node; + *copy = *struct_ref->node; copy->next = merged_globals; merged_globals = copy; - s = s->next; + struct_ref = struct_ref->next; } } @@ -477,11 +477,11 @@ void codegen_node(ParserContext *ctx, ASTNode *node, FILE *out) if (ctx->instantiated_funcs) { - ASTNode *s = ctx->instantiated_funcs; - while (s) + ASTNode *fn_node = ctx->instantiated_funcs; + while (fn_node) { ASTNode *copy = xmalloc(sizeof(ASTNode)); - *copy = *s; + *copy = *fn_node; copy->next = NULL; if (!merged_funcs) { @@ -493,17 +493,17 @@ void codegen_node(ParserContext *ctx, ASTNode *node, FILE *out) merged_funcs_tail->next = copy; merged_funcs_tail = copy; } - s = s->next; + fn_node = fn_node->next; } } if (ctx->parsed_funcs_list) { - StructRef *s = ctx->parsed_funcs_list; - while (s) + StructRef *fn_ref = ctx->parsed_funcs_list; + while (fn_ref) { ASTNode *copy = xmalloc(sizeof(ASTNode)); - *copy = *s->node; + *copy = *fn_ref->node; copy->next = NULL; if (!merged_funcs) { @@ -515,17 +515,17 @@ void codegen_node(ParserContext *ctx, ASTNode *node, FILE *out) merged_funcs_tail->next = copy; merged_funcs_tail = copy; } - s = s->next; + fn_ref = fn_ref->next; } } if (ctx->parsed_impls_list) { - StructRef *s = ctx->parsed_impls_list; - while (s) + StructRef *impl_ref = ctx->parsed_impls_list; + while (impl_ref) { ASTNode *copy = xmalloc(sizeof(ASTNode)); - *copy = *s->node; + *copy = *impl_ref->node; copy->next = NULL; if (!merged_funcs) { @@ -537,7 +537,7 @@ void codegen_node(ParserContext *ctx, ASTNode *node, FILE *out) merged_funcs_tail->next = copy; merged_funcs_tail = copy; } - s = s->next; + impl_ref = impl_ref->next; } } diff --git a/src/codegen/codegen_stmt.c b/src/codegen/codegen_stmt.c index cba55b4..43e5bb5 100644 --- a/src/codegen/codegen_stmt.c +++ b/src/codegen/codegen_stmt.c @@ -70,21 +70,9 @@ static void emit_single_pattern_cond(const char *pat, int id, int is_ptr, FILE * fprintf(out, "strcmp(_m_%d, %s) == 0", id, pat); } } - else if (pat[0] == '\'') - { - // Char literal pattern - if (is_ptr) - { - fprintf(out, "*_m_%d == %s", id, pat); - } - else - { - fprintf(out, "_m_%d == %s", id, pat); - } - } else { - // Numeric or simple pattern + // Numeric, Char literal (removed duplicate branch), or simple pattern if (is_ptr) { fprintf(out, "*_m_%d == %s", id, pat); -- cgit v1.2.3