fix: review problems
This commit is contained in:
@@ -3,12 +3,6 @@
|
||||
#include <compiler/fzl_parser.h>
|
||||
#include <stdio.h>
|
||||
|
||||
char bincond_problem[256];
|
||||
|
||||
// defined in `compiler/analyzer/utility.c`
|
||||
extern bool an_is_compatible(fzl_type_t a, fzl_type_t b, char *ac, char *bc);
|
||||
extern char *an_typetostr(fzl_type_t type, char *classname);
|
||||
|
||||
// Analyze binary conditional nodes
|
||||
fzl_an_res_t analyze_condition(fzl_analyzer_t *analyzer, fzl_node_t *cond_node)
|
||||
{
|
||||
@@ -24,7 +18,7 @@ fzl_an_res_t analyze_condition(fzl_analyzer_t *analyzer, fzl_node_t *cond_node)
|
||||
cond_node->type != FZL_NODETYPE_EQUAL &&
|
||||
cond_node->type != FZL_NODETYPE_NEQUAL))
|
||||
{
|
||||
an_push_error(analyzer, NULL, "node is not typeof binary condition");
|
||||
an_push_error(analyzer, NULL, "node is not a binary conditional operator");
|
||||
return (fzl_an_res_t){.error = true};
|
||||
}
|
||||
|
||||
@@ -54,14 +48,14 @@ fzl_an_res_t analyze_condition(fzl_analyzer_t *analyzer, fzl_node_t *cond_node)
|
||||
if (left.type < FZL_TYPE_INT8)
|
||||
{
|
||||
an_push_error(analyzer, cond_node->binary_op.left->token,
|
||||
"left operand must be number");
|
||||
"left operand must have integer type");
|
||||
return (fzl_an_res_t){.error = true};
|
||||
}
|
||||
|
||||
if (left.type < FZL_TYPE_INT8)
|
||||
{
|
||||
an_push_error(analyzer, cond_node->binary_op.left->token,
|
||||
"right operand must be number");
|
||||
"right operand must have integer type");
|
||||
return (fzl_an_res_t){.error = true};
|
||||
}
|
||||
}
|
||||
@@ -70,7 +64,7 @@ fzl_an_res_t analyze_condition(fzl_analyzer_t *analyzer, fzl_node_t *cond_node)
|
||||
if (right.type < FZL_TYPE_INT8)
|
||||
{
|
||||
an_push_error(analyzer, cond_node->binary_op.right->token,
|
||||
"right operand must be an integer");
|
||||
"right operand must have integer type");
|
||||
return (fzl_an_res_t){.error = true};
|
||||
}
|
||||
|
||||
@@ -89,12 +83,10 @@ fzl_an_res_t analyze_condition(fzl_analyzer_t *analyzer, fzl_node_t *cond_node)
|
||||
if (!an_is_compatible(left.type, right.type, left.classname,
|
||||
right.classname))
|
||||
{
|
||||
snprintf(bincond_problem, sizeof(bincond_problem),
|
||||
"'%s' and '%s' are incompatible",
|
||||
snprintf(an_problem, sizeof(an_problem), "'%s' and '%s' are incompatible",
|
||||
an_typetostr(left.type, left.classname),
|
||||
an_typetostr(right.type, right.classname));
|
||||
an_push_error(analyzer, cond_node->binary_op.right->token,
|
||||
bincond_problem);
|
||||
an_push_error(analyzer, cond_node->binary_op.right->token, an_problem);
|
||||
return (fzl_an_res_t){.error = true};
|
||||
}
|
||||
}
|
||||
@@ -110,7 +102,7 @@ fzl_an_res_t analyze_condition(fzl_analyzer_t *analyzer, fzl_node_t *cond_node)
|
||||
else if (!an_is_compatible(left.type, right.type, left.classname,
|
||||
right.classname))
|
||||
{
|
||||
snprintf(bincond_problem, sizeof(bincond_problem),
|
||||
snprintf(an_problem, sizeof(an_problem),
|
||||
"equality not supported between %s and %s",
|
||||
an_typetostr(left.type, left.classname),
|
||||
an_typetostr(right.type, right.classname));
|
||||
|
||||
Reference in New Issue
Block a user