fix: review problems

This commit is contained in:
samsonium
2026-10-27 15:40:25 +03:00
parent c61322718d
commit dc80de66e4
21 changed files with 197 additions and 179 deletions
+12 -15
View File
@@ -5,12 +5,6 @@
#include <stddef.h>
#include <stdio.h>
char block_problem[256];
// defined in `compiler/analyzer/utility.c`
extern fzl_type_t an_toktotype(fzl_token_t *tok);
extern char *an_typetostr(fzl_type_t type, char *classname);
// Analyze block
fzl_an_res_t analyze_block(fzl_analyzer_t *analyzer, fzl_node_t *block_node)
{
@@ -19,8 +13,8 @@ fzl_an_res_t analyze_block(fzl_analyzer_t *analyzer, fzl_node_t *block_node)
if (!block_node || block_node->type != FZL_NODETYPE_BLOCK)
{
snprintf(block_problem, sizeof(block_problem), "node is not typeof BLOCK");
an_push_error(analyzer, NULL, block_problem);
snprintf(an_problem, sizeof(an_problem), "node is not a block");
an_push_error(analyzer, NULL, an_problem);
return (fzl_an_res_t){.error = true};
}
@@ -32,7 +26,7 @@ fzl_an_res_t analyze_block(fzl_analyzer_t *analyzer, fzl_node_t *block_node)
{
if (has_return)
an_push_warning(analyzer, block_node->list.entries[i]->token,
"this node will never execute");
"this statement will never execute");
fzl_an_res_t entry_res =
analyze_common(analyzer, block_node->list.entries[i]);
@@ -65,10 +59,11 @@ fzl_an_res_t analyze_block(fzl_analyzer_t *analyzer, fzl_node_t *block_node)
{
if (!has_return || block_node->list.entry_count < 1)
{
snprintf(block_problem, sizeof(block_problem),
"expected 'return <%s>' in function because return type is %s",
rettype_str, rettype_str);
an_push_error(analyzer, block_node->token, block_problem);
snprintf(an_problem, sizeof(an_problem),
"'return <%s>' is expected in the function with non-null "
"return type",
rettype_str);
an_push_error(analyzer, block_node->token, an_problem);
return (fzl_an_res_t){.error = true};
}
@@ -76,10 +71,12 @@ fzl_an_res_t analyze_block(fzl_analyzer_t *analyzer, fzl_node_t *block_node)
block_node->list.entries[block_node->list.entry_count - 1];
if (last_node->type != FZL_NODETYPE_RETURN)
{
snprintf(block_problem, sizeof(block_problem),
// NOTE: replace with ghost walker to check if all branch return an
// expected value type
snprintf(an_problem, sizeof(an_problem),
"expected last statement in block to be 'return <%s>'",
rettype_str);
an_push_error(analyzer, last_node->token, block_problem);
an_push_error(analyzer, last_node->token, an_problem);
return (fzl_an_res_t){.error = true};
}
}