summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/analysis/typecheck.c1
-rw-r--r--src/codegen/codegen_main.c32
-rw-r--r--src/codegen/codegen_stmt.c14
-rw-r--r--src/lsp/json_rpc.c2
-rw-r--r--src/lsp/lsp_analysis.c2
5 files changed, 20 insertions, 31 deletions
diff --git a/src/analysis/typecheck.c b/src/analysis/typecheck.c
index a0a2df1..e83bb4b 100644
--- a/src/analysis/typecheck.c
+++ b/src/analysis/typecheck.c
@@ -15,6 +15,7 @@ static void tc_error(TypeChecker *tc, Token t, const char *msg)
static void tc_enter_scope(TypeChecker *tc)
{
Scope *s = malloc(sizeof(Scope));
+ if (!s) return;
s->symbols = NULL;
s->parent = tc->current_scope;
tc->current_scope = s;
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);
diff --git a/src/lsp/json_rpc.c b/src/lsp/json_rpc.c
index 9baf33e..ffb5d1f 100644
--- a/src/lsp/json_rpc.c
+++ b/src/lsp/json_rpc.c
@@ -114,7 +114,7 @@ void handle_request(const char *json_str)
"\"signatureHelpProvider\":{\"triggerCharacters\":[\"(\"]},"
"\"completionProvider\":{"
"\"triggerCharacters\":[\".\"]}}}}";
- fprintf(stdout, "Content-Length: %ld\r\n\r\n%s", strlen(response), response);
+ fprintf(stdout, "Content-Length: %zu\r\n\r\n%s", strlen(response), response);
fflush(stdout);
}
else if (strcmp(method, "textDocument/didOpen") == 0 ||
diff --git a/src/lsp/lsp_analysis.c b/src/lsp/lsp_analysis.c
index 2a07990..088bede 100644
--- a/src/lsp/lsp_analysis.c
+++ b/src/lsp/lsp_analysis.c
@@ -26,7 +26,7 @@ static void send_json_response(cJSON *root)
char *str = cJSON_PrintUnformatted(root);
if (str)
{
- fprintf(stdout, "Content-Length: %ld\r\n\r\n%s", strlen(str), str);
+ fprintf(stdout, "Content-Length: %zu\r\n\r\n%s", strlen(str), str);
fflush(stdout);
free(str);
}